获取远程数据显示乱码

获取远程数据显示乱码

帮帮我啊,又出现问题了^_-
<?php
@header("Content-type:text/html; charset=utf-8");
//取得远程主机的相内容:标题;
class get_url_content
{
var $url;
var $content;

function __construct()
{
  
}
function getcontent($url)
{
  $urlfile=file_get_contents($url);
  if (!$urlfile)
  {
   return 'errinfo1';
   return false;
  }else{
   $reg1="/<head>(.*)<\/head>/iU";
   $reg2="/<title>(.*)<\/title>/iU";
   $head=preg_match($reg2,$urlfile,$headfile);
   if (!$head)
   {
    return 'eerr';
    return false;
   }else{
    $tit=preg_match($reg2,$urlfile,$titfile);
    if(!$tit)
    {
     return 'errinfo3';
     return false;
    }else{
     $this->charset=$bm[1];
     return $titfile[1];
    }
   }
   
  }
}
function charset (){
  return $this->charset;
}
  
}
$f=new get_url_content;
echo $f->getcontent('http://www.163.com/')
?>

这个文件存贮为 utf-8

还有就是,我去取那些编码为utf-8就显示正常
要怎么才能让它们兼容啊?(就是不管远程内容编码为什么,都可以显示?)

我想分析他的编码,可是还是不行

<?php
@header("Content-type:text/html; charset=gb2312");
//取得远程主机的相内容:标题;
class get_url_content
{
var $url;
var $content;

function __construct()
{
  
}
function getcontent($url)
{
  $urlfile=@file_get_contents($url);
  if (!$urlfile)
  {
   return '无法链接';
   return false;
  }else{
   $reg1="/<head>(.*)<\/head>/iU";
   $reg2="/<title>(.*)<\/title>/iU";
   $head=preg_match($reg2,$urlfile,$headfile);//本来是查询<head>区域的,可是不知道怎么的不行
   if (!$head)
   {
    return '<head>区域的不可用';
    return false;
   }else{
    $tit=preg_match($reg2,$urlfile,$titfile);
    if(!$tit)
    {
     return '没找到可用标题';
     return false;
    }else{
     return $titfile[1];
    }
   }
   
  }
}

  
}
$f=new get_url_content;
echo $f->getcontent('http://www.163.com/')
?>
这个文件存贮的不是utf-8就能正常显示