Home  >  Article  >  Backend Development  >  PHP implements output xml attributes

PHP implements output xml attributes

*文
*文Original
2017-12-26 10:27:461697browse

How to output xml attributes in php? This article mainly introduces the method of PHP outputting XML attributes, and analyzes the usage skills of PHP's method of operating XML file attributes with examples. I hope to be helpful.

The example in this article describes the method of php outputting xml attributes. Share it with everyone for your reference. The specific analysis is as follows:

This code demonstrates through a simple example how php reads an xml file and outputs xml attributes


<?php
  $xml = simplexml_load_file("books.xml");
  foreach($xml->book[0]->author->attributes() AS $a => $b) {
   echo "$a = $b <br />";
  }
?>


xml file content is as follows


<library>
  <book>
   <title>A</title>
   <author gender="female">B</author>
   <description>C</description>
  </book>
  <book>
   <title>C</title>
   <author gender="male">D</author>
   <description>E</description>
  </book>
  <book>
   <title>F</title>
   <author gender="male">G</author>
   <description>H</description>
  </book>
</library>

Related recommendations:

PHP xml parsing and Introduction to the use of generated SimpleXML

Various methods of PHP XML operation analysis (more detailed)

PHP XML and array conversion details

The above is the detailed content of PHP implements output xml attributes. For more information, please follow other related articles on the PHP Chinese website!

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