php解析XML数据

PHP 作者:hello程序员 2022-05-02 12:22:36 阅读:106

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

}


关注公众号:拾黑(shiheibook)了解更多

[广告]赞助链接:

下软件就上简单下载站:https://www.jdsec.com/
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/

公众号 关注网络尖刀微信公众号
随时掌握互联网精彩
赞助链接