How to get HTML page title using php?

How to get HTML page title using php? I created a php network crawler, and I want to implement this function in my crawler so that it has a page name and URLs. Thanks in advance. Use of preg_match is possible.

+3
source share
1 answer

Would that 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";
+9
source

Source: https://habr.com/ru/post/1790317/


All Articles