[PHP] PHP解析 XML 数据 →→→→→进入此内容的聊天室

来自 , 2019-04-24, 写在 PHP, 查看 108 次.
URL http://www.code666.cn/view/c5658c71
  1. //xml string
  2. $xml_string="<?xml version='1.0'?>
  3. <users>
  4. <user id='398'>
  5. <name>Foo</name>
  6. <email>foo@bar.com</name>
  7. </user>
  8. <user id='867'>
  9. <name>Foobar</name>
  10. <email>foobar@foo.com</name>
  11. </user>
  12. </users>";  
  13.  
  14. //load the xml string using simplexml
  15. $xml = simplexml_load_string($xml_string);  
  16.  
  17. //loop through the each node of user
  18. foreach ($xml->user as $user)
  19. {
  20.         //access attribute
  21.         echo $user['id'], ' ';
  22.         //subnodes are accessed by -> operator
  23.         echo $user->name, ' ';
  24.         echo $user->email, '<br />';
  25. }
  26.  

回复 "PHP解析 XML 数据"

这儿你可以回复上面这条便签

captcha