欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP解析 XML 数据

程序员文章站 2022-03-05 12:11:05
...
  1. $xml_string="
  2. ben
  3. A
  4. h2o
  5. K
  6. ";
  7. //load the xml string using simplexml function
  8. $xml = simplexml_load_string($xml_string);
  9. //loop through the each node of molecule
  10. foreach ($xml->molecule as $record)
  11. {
  12. //attribute are accessted by
  13. echo $record['name'], ' ';
  14. //node are accessted by -> operator
  15. echo $record->symbol, ' ';
  16. echo $record->code, '
    ';
  17. }
复制代码

PHP, XML