如何使用php获取HTML页面的标题?

3 html php title

如何使用php获取HTML页面的标题?我已经制作了一个php网络抓取工具,我想在我的抓取工具中实现此功能,以便它具有页面名称和网址.提前致谢.可能使用preg_match.

And*_*eas 10

这会有帮助吗?

$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";
Run Code Online (Sandbox Code Playgroud)