我正在尝试从网站获取“标题”,目前我正在使用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(!@file_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";
}
}
有没有一种快速的方法可以从每一页获取“标题”?