如何在PHP file_get_contents()中修复UTF-8字符 [英] How fix UTF-8 Characters in PHP file_get_contents()
本文介绍了如何在PHP file_get_contents()中修复UTF-8字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用file_get_contents($url)
并回显此字符时,它返回一个奇异字符.
When I am using file_get_contents($url)
, and when I echo this, it returns an exotic character.
但是它只能在某些网站上看到并且在其他网站上可以正常工作:
But it can be seen only in some websites and works correctly in other websites:
我的代码是:
<?php
header ( "Content-Type: text/html;charset=utf-8" );
$url ="http://www.varzesh3.com/news/1307290";
echo $go_to = file_get_contents($url);
?>
推荐答案
根据PHP手册:
如果file_get_contents有问题,您可以使用此代码!
you can use this code, if you have problem with file_get_contents!
<?php
function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
return mb_convert_encoding($content, 'UTF-8',
mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}
?>
这篇关于如何在PHP file_get_contents()中修复UTF-8字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文