当前页面是1.php页面,utf-8编码(在zend studio点右键,更改文件本身为utf-8编码),要去拿一个网站的3.php页面,对方是gb2312的编码(注意是文件本身,而不是里面的charset),我拿到后怎么转换?
<?php

$content = file_get_contents("http://www.XXX.com/3.php");
$content =  iconv('gbk','utf-8//ignore',$content)  ;


echo $content;
?>

如果上面没有iconv库,需要用一个编码对照表。程序参考了dedecms

其实上面还应该先探测一下是不是gbk编码

<?php
/*
*QQ: 290359552
* conver to Utf8 if $str is not equals to 'UTF-8'
*/
function convToUtf8($str)
{
if(
mb_detect_encoding($str,"UTF-8, ISO-8859-1, GBK")!="UTF-8" )
{

return 
iconv("gbk","utf-8",$str);

}
else
{
return
$str;
}

}
?>

相关文章:

  • 2021-06-24
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2022-01-24
猜你喜欢
  • 2022-12-23
  • 2021-12-20
  • 2022-01-20
  • 2022-12-23
相关资源
相似解决方案