Suppose another domain provides me with a json
How do I get it and print it out using php? ? !
给我你的怀抱2017-06-14 10:51:41
// 初始化cURL
$ch = curl_init();
// 设置选项
curl_setopt($ch, CURLOPT_URL, '你的网址');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
// 执行并获取文档内容
$contents = curl_exec($ch);
// 释放 curl
curl_close($ch);
// 打印获得的数据
print_r( json_decode($contents) );
世界只因有你2017-06-14 10:51:41
The two people above said the same thing, so I won’t say more. The question is, is your json a standard json? If so, I just assume that you collect it from JD.com (not counting JD.com providing it to you) ), the json obtained is used by javascript, which is not standard for php. You must complete the quotation marks before it can be used by php