How can I get the title of an HTML page using php?

后端 未结 1 1732
日久生厌
日久生厌 2020-12-19 18:49

How can I get the title of an HTML page using php? I\'ve made a php web crawler and I want to implement this feature into my crawler so that it will have the name of the pag

相关标签:
1条回答
  • 2020-12-19 19:34

    Would this help?

    $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";
    
    0 讨论(0)
提交回复
热议问题