脚本宝典收集整理的这篇文章主要介绍了php – file_get_contents()将UTF-8转换为ISO-8859-1,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
但是file_get_contents()将UTF-8字符集(charset,雅虎使用的)内容转换为ISO-8859-1.
尝试:
$filename = "http://seArch.yahoo.COM/search;_ylt=A0oG7lpgGp9NTSYaiQBXNyoA?p=naj%C5%A1%C5%A5astnej%C5%A1%C3%AD&fr2=sb-top&fr=yfp-t-701&tyPE_param=&rd=PRef"; echo file_get_contents($filename);
脚本为
header('Content-Type: text/htML; charset=UTF-8');
要么
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
要么
$er = mb_convert_encoding($filename,'UTF-8');
要么
$s2 = iconv("ISO-8859-1","UTF-8",$filename );
要么
echo utf8_encode(file_get_contents($filename));
没有帮助,因为在获取网页内容特殊字符作为šťž被替换为问号???
我将不胜感激任何帮助.
您可以使用stream_context_create
为file_get_contents创建自定义stream context,明确声明您接受UTF-8:
$opts = array('http' => array('header' => 'Accept-Charset: UTF-8,*;q=0')); $context = stream_context_create($opts); $filename = "http://search.yahoo.com/search;_ylt=A0oG7lpgGp9NTSYAiQBXNyoA?p=naj%C5%A1%C5%A5astnej%C5%A1%C3%AD&fr2=sb-top&fr=yfp-t-701&type_param=&rd=pref"; echo file_get_contents($filename,false,$context);
以上是脚本宝典为你收集整理的php – file_get_contents()将UTF-8转换为ISO-8859-1全部内容,希望文章能够帮你解决php – file_get_contents()将UTF-8转换为ISO-8859-1所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。