Skip to content

Instantly share code, notes, and snippets.

@davidjmemmett
Created August 28, 2010 16:18
Show Gist options
  • Save davidjmemmett/555305 to your computer and use it in GitHub Desktop.
Save davidjmemmett/555305 to your computer and use it in GitHub Desktop.
<?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