1

I am using this code in order to show data onto php page:

$url = 'http://example.com';

//Initiate cURL and pass it the URL we want to retrieve.
$ch = curl_init($url);

//Tell cURL to return the output as a string.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

//Execute the cURL request and return the output to a string.
$response = curl_exec($ch);

//Print out the response to the browser.
echo mb_detect_encoding($response);
echo utf8_encode($response);

The last two lines contain debugging methods I've tried lastly. Mb_detect_encodign returns UTF-8 at my content, even if the original source URL is including windows-1253 encoding in its charset.

The content is not being displayed correctly - It returns characters like: õìðëçñþóôå instead of the original content which is expected in greek characters.

I know that Windows-1253 is not supported by PHP, however, it seems that phpcurl is transforming it to UTF8 - but in my case, its not being done correctly.

I tried adding a php header with no luck. Also tried adding mb_convert_encoding with no luck aswell.

Any advises?

John Greco
  • 45
  • 6

1 Answers1

1

Solved this by changing to file_get_contents :

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-7', true)); 
} 

print file_get_contents_utf8('http://example.com/');
John Greco
  • 45
  • 6