我该如何使用PHP获取HTML页面的标题?我制作了一个PHP网络爬虫,并希望将此功能实现到我的爬虫中,以便它可以获得页面的名称和URL。谢谢。可能需要使用preg_match。
这会有帮助吗?
$myURL = 'http://www.google.com';
if (preg_match(
'/<title>(.+)<\/title>/',
file_get_contents($myURL),$matches)
&& isset($matches[1] )
$title = $matches[1];
else
$title = "Not Found";