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

11,130

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";
Share:
11,130
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin about 2 years

    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 page and the url. Thanks in advance. Possibly using preg_match.

  • ARUN
    ARUN about 10 years
    This function is not working for some urls. for example : marketwired.com/press-release/…
  • shasi kanth
    shasi kanth about 9 years