먼저 웹 페이지의 HTML을 가져오고 일반적으로 페이지 본문의 왼쪽 또는 오른쪽에 나타나는 href 링크를 제거합니다. Href 링크는 제거 중이지만 해당 레이블은 제거되지 않습니다.html 링크를 제거하고 html dom 파서를 사용하여 레이블을 지정하십시오.
예 :
<a href='http://test.blogspot.com/2012/11/myblog.html'>London</a>
링크가 제거되고 있지만 그것의 라벨 즉 '런던'. html 소스에서 전체 행을 제거하려면 어떻게해야합니까? 나는 그것을 위해 다음 코드를 사용하고 있습니다 :
은 당신이해야 할 모든는 erraser()
기능 두 다음 매개 변수 링크의 변수, 어떤 텍스트를 제공합니다 :
$string = strip_tags($html_source_code, '<a>', TRUE);
function strip_tags($text, $tags = '', $invert = FALSE) {
preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
$tags = array_unique($tags[1]);
if(is_array($tags) AND count($tags) > 0) {
if($invert == FALSE) {
return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
}
else {
return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
}
}
elseif($invert == FALSE) {
return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
}
return $text;
}
이제
그럼,'return $ text;'는 무엇을 기대합니까? – samayo