【发布时间】:2016-03-15 18:54:25
【问题描述】:
考虑以下网址: click here
日文字符有一些编码。我电脑上的 Firefox 浏览器能够自动检测并显示字符。另一方面,对于 Chrome,我必须手动将编码更改为“Shift_JIS”才能看到日文字符。
如果我尝试通过 PHP-cURL 访问内容,编码的文本会出现这样的乱码
����ϕi�̂��ƂȂ��I�����������N�`�R�~�T�C���������������i�A�b �g�R�X���j�ɂ��������I
我试过了:
curl_setopt($ch, CURLOPT_ENCODING, 'Shift_JIS');
我也试过(下载 curl 响应后):
$output_str = mb_convert_encoding($curl_response, 'Shift_JIS', 'auto');
$output_str = mb_convert_encoding($curl_response, 'SJIS', 'auto');
但这也不起作用。
这是完整的代码
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: en-US,en;q=0.5',
'Connection: keep-alive'
));
//curl_setopt($ch, CURLOPT_ENCODING, 'SJIS');
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
【问题讨论】:
-
会不会被压缩了? stackoverflow.com/questions/310650/…
-
可能是。 cURL中如何处理?
-
在我链接的页面上有说明
-
很遗憾,事实并非如此。
标签: php curl character-encoding