Php 使用cURL时返回的奇数字符
我使用cURL下载不同页面上的内容。其中一些返回奇数字符,如�. 我做错了什么?在下面发布我的代码:Php 使用cURL时返回的奇数字符,php,curl,Php,Curl,我使用cURL下载不同页面上的内容。其中一些返回奇数字符,如�. 我做错了什么?在下面发布我的代码: curl_setopt($curl_handle, CURLOPT_URL, 'http://www.centernail.se/'); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_handle, CURLOPT_HEADER, false); curl_setopt($curl_h
curl_setopt($curl_handle, CURLOPT_URL, 'http://www.centernail.se/');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_HEADER, false);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl_handle, CURLOPT_ENCODING , '');
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.165 Safari/535.19');
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 20);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
这意味着您没有处理编码。页面使用特定的编码进行编码。您或您正在将其输出到的浏览器,或您正在查看下载页面的任何东西,都在使用特定的编码对其进行解释。如果这两个字符不匹配,就会得到错误的字符解释。就这么简单 您正在决定用什么编码来解释数据。您需要确保输出的数据与该编码匹配。最好的方法是使用UTF-8,并检查页面的HTTP头或HTML元头(按此顺序),以确定其编码方式,如果是其他编码,则将其转换为UTF-8
请参阅和。转换结果的编码或更改输出的编码
- 要转换,请尝试php函数
- 要更改输出,请更改