ABE ABE - 1 month ago 11x
PHP Question

file_get_contents show characters of utf-8 like question marks

$str = "https://www.google.com/search?q=sd";
echo file_get_contents($str);

I'm try to load page from google with the function file_get_contents, but the output of chracters of utf-8 showing like question mark.

I've tried all the possibilities introduced here:
file_get_contents() converts UTF-8 to ISO-8859-1
But the problem is still not resolved.

I would appreciate any help very.


I see that the problem exists through Google, other sites content is displayed correctly.

enter image description here




$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;


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