我試圖從網站獲得「冠軍」獲得元數據,在我使用preg_match
拿到冠軍的那一刻,但它是非常緩慢的加載。最快的方式從網站
我在看什麼:
這通過一個函數傳遞鏈接:
<?php
foreach($savedLinks as $s)
{
echo "<div class='savedLink'>";
echo "<h5>" . getMetaData($s) . "</h5>";
echo "<a href='" . $s . "'>" . $s . "</a><br />";
echo "</div>";
}
?>
此功能抓起,從每個網站傳遞的標題:
function getMetaData($url)
{
if([email protected]_get_contents($url))
{
return "";
}
else
{
if(preg_match('/<title>(.+)<\/title>/',file_get_contents($url),$matches) && isset($matches[1]))
return $matches[1];
else
return "Not Found";
}
}
有一種快速的方法從每個頁面獲得「標題」?
一個字[DOM]( http://php.net/manual/en/book.dom.php) – 2013-10-08 00:46:04
我試過DOM,但是當試圖從大約10頁獲得'標題'時,它開始加載非常慢。 –