php curl windows-1253编码为utf8时出现问题
我使用此代码是为了在php页面上显示数据:php curl windows-1253编码为utf8时出现问题,curl,iframe,utf-8,php-curl,mb-convert-encoding,Curl,Iframe,Utf 8,Php Curl,Mb Convert Encoding,我使用此代码是为了在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, CURLOP
$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_编码,但也没有成功
有什么建议吗?通过更改为
文件获取内容解决了这个问题:
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/');