iLeichun

当前位置: 首页 > PHP

PHP如何解析XML

分类:PHP   来源:网络   时间:2011-03-12 20:18:04

PHP解析XML数据

//xml string
$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 />¹;
}

 

文章来源:侠客站长站(www.xkzzz.com) 详文参考:http://www.xkzzz.com/zz/netbc/php/201009/22-56347.html

更多