- file_get_contents: documentation ( source)
- preg_match: documentation ( source)
- trim: documentation ( source)
- preg_replace: documentation ( source)
<?php
function get_title($url){
$fp = file_get_contents($url);
if (!$fp)
return null;
$res = preg_match("/<title>(.*)<\/title>/siU", $fp, $title_matches);
if (!$res)
return null;
$title = preg_replace('/\s+/', ' ', $title_matches[1]);
$title = trim($title);
return $title;
}
get_title("http://google.com");