我正在使用此代码将数据显示到 php 页面上:
$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);
最后两行包含我最后尝试过的调试方法。Mb_detect_encodign 在我的内容中返回 UTF-8,即使原始源 URL 在其字符集中包含 windows-1253 编码。
内容显示不正确 - 它返回如下字符:õìðëçñþóôå,而不是希腊字符中预期的原始内容。
我知道 PHP 不支持 Windows-1253,但是,似乎 phpcurl 正在将其转换为 UTF8 - 但就我而言,它没有正确完成。
我尝试添加一个没有运气的 php 标头。还尝试添加 mb_convert_encoding 也没有运气。
有什么建议吗?