나는 this question을 보았지만, 내가 찾고있는 것을 정말로 만족시키지 못한다. 그 질문의 대답은 메타 설명 태그에서 들어 올린 것이고, 두 번째는 이미 시체를 가지고있는 기사의 발췌 부분을 생성하는 것입니다.PHP 문지기 기사 가독성과 같은 발췌문
내가하고 싶은 것은 실제로 가독성과 마찬가지로 문서의 처음 몇 문장을 얻는 것입니다. 이것에 가장 좋은 방법은 없을까요? HTML 구문 분석? 여기에 제가 현재 사용하고있는 것이 있습니다 만, 이것은별로 신뢰할만한 것이 아닙니다.
function guessExcerpt($url) {
$html = file_get_contents_curl($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'description')
$description = $meta->getAttribute('content');
}
return $description;
}
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
[php-readability] (http://code.fivefilters.org/phpreadability/) – j0k