I\'m doing a bookmarking system and looking for the fastest (easiest) way to retrieve a page\'s title with PHP.
It would be nice to have something like $title
or making this simple function slightly more bullet proof:
function page_title($url) {
$page = file_get_contents($url);
if (!$page) return null;
$matches = array();
if (preg_match('/(.*?)<\/title>/', $page, $matches)) {
return $matches[1];
} else {
return null;
}
}
echo page_title('http://google.com');