搜索:
首页 >> php编程 >> PHP XML数据解析代码

PHP XML数据解析代码

Asp之家 2019-3-25 投递文章

代码如下:


//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 />';
}


Tags:PHP  XML 
相关文章
手机版 php编程 Asp之家 Aspxhome.com
闽ICP备06017341号