Home > Backend Development > PHP Tutorial > curl get获取到一个utf-8 json字符串,用json_decode解析说格式不对。

curl get获取到一个utf-8 json字符串,用json_decode解析说格式不对。

WBOY
Release: 2016-06-20 12:33:44
Original
1601 people have browsed it

    $ch = curl_init();//初始化curl    curl_setopt($ch,CURLOPT_URL,$url);    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);    curl_setopt($ch, CURLOPT_HEADER, 0);            $data=curl_exec($ch);    print_r(json_decode($data));    echo json_last_error_msg();//提示符号错误
Copy after login


用浏览器输入$url,确实反馈回来一个json数据。怎么弄?bom去头又怎么弄。好像去不掉。


回复讨论(解决方案)

.....
$data=curl_exec($ch);
echo base64_encode($data);
贴出结果

PGh0bWw+DQo8aGVhZD48dGl0bGU+MzAxIE1vdmVkIFBlcm1hbmVudGx5PC90aXRsZT48L2hlYWQ+DQo8Ym9keSBiZ2NvbG9yPSJ3aGl0ZSI+DQo8Y2VudGVyPjxoMT4zMDEgTW92ZWQgUGVybWFuZW50bHk8L2gxPjwvY2VudGVyPg0KPGhyPjxjZW50ZXI+bmdpbng8L2NlbnRlcj4NCjwvYm9keT4NCjwvaHRtbD4NCg==

加上
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template