(.*)<\/title>/si', $html, $matches); $title = $matches[1][0]; // Get encoding from charset attribute preg_match_all('//i', $html, $matches); $encoding = strtoupper($matches[1][0]); // Convert to UTF-8 from the original encoding if (function_exists('mb_convert_encoding')) { $title = @mb_convert_encoding($title, 'UTF-8', $encoding); } if (utf8_strlen($title) > 0) { return $title; } else { // No title, so return filename $uriparts = explode('/', $url); $filename = end($uriparts); unset($uriparts); return $filename; } } else { return false; } } echo getTitle($_GET['url']);