开发者

Detection - the title of the URL and the URL

How to detect, if there is any URL in the text and title it has (if any)?

If there is one, then it should change the开发者_StackOverflow URL:

from: http://stackoverflow.com

into:

<detected:url="http://stackoverflow.com"/>

I need also to retrieve titles from external links like this example:

<title:http://stackoverflow.com/="the actual title from the stackoverflow"/>


This is for single URL case:

$url = "http://www.stackoverflow.com/";

$check_result = get_detected_and_title( $url );


function get_detected_and_title( $url )
{
    $detected = '<detected:url="'.$url.'"/>';
    $title = '';
    $tmp_html = file_get_contents( $url );
    preg_match('/<title>(.*)<\/title>/', $tmp_html, $res);
    $title = '<title:'.$url.'="'.$res[1].'"/>';

    return array( $detected, $title );
}

Actually, after looking through SO's pages, I think this is more close to what you looking for. Although it needs some adjustment: How to mimic StackOverflow Auto-Link Behavior

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜