PHP解析JSON与XML,可解析远程json
PHP解析JSON与XML,可解析远程json$data = file_get_contents($url);//目的页面内容获取$t = json_decode($data,1);//转换为PHP数组
//处理...
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlo);//数据发送地址
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//发送的数据数组
curl_exec($ch);
与大多数流行的 Web 服务如 twitter 通过开放 API 来提供数据一样,它总是能够知道如何解析 API 数据的各种传送格式,包括 JSON,XML 等等。PHP解析JSON数据
$json_string='{"id":1,"name":"foo","email":"foo@foobar.com","interest":["wordpress","php"]} ';
$obj=json_decode($json_string);
echo $obj->name; //prints foo
echo $obj->interest; //prints php
PHP解析XML 数据
$xml_string="<?xml version='1.0'?>
<users>
<user id='398'>
<name>Foo</name>
<email>foo@bar.com</name>
</user>
<user id='867'>
<name>Foobar</name>
<email>foobar@foo.com</name>
</user>
</users>";
//load the xml string using simplexml
$xml = simplexml_load_string($xml_string);
//loop through the each node of user
foreach ($xml->user as $user)
{
//access attribute
echo $user['id'], ' ';
//subnodes are accessed by -> operator
echo $user->name, ' ';
echo $user->email, '<br />';
}本文摘自:http://www.cnblogs.com/yilee/archive/2011/08/18/2145080.html
页:
[1]