मैंने this question देखा है, लेकिन यह वास्तव में मुझे संतुष्ट नहीं करता है कि मैं क्या देख रहा हूं। उस प्रश्न का उत्तर या तो था: मेटा विवरण टैग से उठाओ, और दूसरा उस लेख के लिए एक अंश उत्पन्न कर रहा था जिसमें आपके पास पहले से ही शरीर है।पीएचपी स्क्रैप अनुच्छेद उद्धरण जैसे पठनीयता
मैं जो करना चाहता हूं वह वास्तव में आलेख के पहले कुछ वाक्यों को प्राप्त करता है, जैसे पठनीयता। इसके लिए सबसे अच्छी विधि क्या नहीं है? एचटीएमएल पार्सिंग? यहां मैं वर्तमान में उपयोग कर रहा हूं, लेकिन यह बहुत विश्वसनीय नहीं है।
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/php-readability/) – j0k