问题
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:
My code is:
<?php
header ( "Content-Type: text/html;charset=utf-8" );
$url ="http://www.varzesh3.com/news/1307290";
echo $go_to = file_get_contents($url);
?>
回答1:
According to PHP manual:
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));
}
?>
回答2:
and set header, it need to be first witch php send to client browser
header('Content-Type: text/html; charset =utf-8');
来源:https://stackoverflow.com/questions/35679900/how-fix-utf-8-characters-in-php-file-get-contents