Home  >  Article  >  Backend Development  >  PHP parses XML data

PHP parses XML data

WBOY
WBOYOriginal
2016-07-25 08:42:421205browse
  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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn