file_get_contents show characters of utf-8 like question marks

∥☆過路亽.° 提交于 2019-12-08 01:33:25

[php]

//charset.php?case=1
//charset.php?case=2
//charset.php?case=3

$case = isset($_GET['case']) ? $_GET['case'] : 1;

if( !in_array($case,range(1,3)) ) $case = 1;


if( $case==1 ) {
    header("Content-type: text/html; charset=tis-620"); //http://htmlpurifier.org/docs/enduser-utf8.html
    $str = "https://www.google.co.th/search?q=sd";
}

if( $case==2 ) {
    header("Content-type: text/html; charset=ISO-8859-1");
    $str = "https://www.google.de/search?q=sd";
}   

if( $case==3 ) {
    header("Content-type: text/html; charset=ISO-8859-9");
    $str = "https://www.google.com.tr/search?q=sd";
}


$data = file_get_contents($str);
echo $data;

[/php]

as you can see ... the correct charset in php header is the solution

try once this code it worked for me ..

    <?php 
$abc = array('http' => array('header' => 'Accept-Charset: UTF-8, *;q=0'));
$some_context = stream_context_create($abc);
$filename = "https://www.google.com/search?q=sd";
echo file_get_contents($filename, false, $some_context);
    ?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!