我有一个PHP脚本,从网页中刮去元标记和标题。它应该回应他们,但是什么都不做。我试过error_reporting(E_ALL)
,ini_set('display_errors',1);
等,但他们不提供任何推理背后。PHP不显示错误或回声
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_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$html = file_get_contents_curl("http://www.tomato.co.uk/");
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
$title = $nodes->item(0)->nodeValue;
echo $title;
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'description')
$description = $meta->getAttribute('content');
echo $description;
if($meta->getAttribute('name') == 'keywords')
$keywords = $meta->getAttribute('content');
echo $keywords;
}
难道是你在这里压制错误:@ $ doc-> loadHTML($ html); ? – Kei
当我在这里运行它时,你的脚本就可以工作。检查你的服务器日志,可能有东西在那里报告。 – Barmar
@Kei你会推荐删除吗? – user3339235