2011-09-30 5 views
3

텍스트 및 제목에 URL이 있으면 감지하는 방법은 무엇입니까?검색 - URL 및 URL의 제목

가있는 경우, 다음의 URL 변경해야합니다 :

을에서 : http://stackoverflow.com

로 :이 예와 같이 외부 링크에서 제목을 검색하는 것이 필요

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

:

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

이것은 다릅니다. 모든 URL이 "http?"로 시작합니까? URL 제목을 나타내는 것은 무엇입니까? –

+0

@tandu 사용자가 게시 한 데이터를 구문 분석하기 때문에. 제목은 태그에서 감지 된 사이트 URL 제목입니다. – Lucas

+0

XML입니까? 그렇다면 유효한 XML이 아닙니다. – icktoofay

답변

1

단일 URL의 경우 :

$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); 
} 

는 사실, SO의 페이지를 찾고 후, 나는 이것이 당신이 찾고있는 무엇에 더 가까운 것 같아요. 약간의 조정이 필요하지만 : How to mimic StackOverflow Auto-Link Behavior