Created
August 28, 2010 16:18
-
-
Save davidjmemmett/555305 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getPageTitle($url, $to_encoding) | |
{ | |
$fh = fopen($url, 'r'); | |
$content = ""; | |
$title = ""; | |
while (!feof($fh)) | |
{ | |
$content .= fread($fh, 8192); | |
if(preg_match("/<title>(.+)<\/title>/i", $content, $matches)) | |
{ | |
$title = $matches[1]; | |
} | |
} | |
$encoding = mb_detect_encoding($title, "JIS, eucjp-win, sjis-win"); | |
return mb_convert_encoding($title, $to_encoding, $encoding); | |
} | |
echo getPageTitle("http://mixi.jp/show_profile.pl?id=1305207", "UTF-8"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment