2013-03-14 51 views
2

下面我有一段代码来通过API返回一些信息。格式curl结果在php

$page = 'http://api.duedil.com/sandbox/v2/company/03977902.json? fields=get_all&api_key=***********'; 
$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $page); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_exec($ch); 
curl_close($ch); 

这打印出如下结果http://www.visitrack.co.uk/testdata.php

什么,我试图做的是将各个变量的结果分开。

感谢

+4

使用['json_decode'(http://www.php.net/manual/en/function.json-decode。 PHP) – Jon 2013-03-14 20:12:01

回答

0

像这样的东西应该做的伎俩:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $page); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // forces curl_exec() to return page as a string 
$json = curl_exec($ch); 
curl_close($ch); 
$data = json_decode($json, TRUE); // parse json string to array 
print_r($data);