This paper illustrates the application of the simplexml of Php+xml programming. Share to everyone for your reference. Specifically as follows:
SimpleXML's core idea: manipulating an XML file in an object-oriented manner, which converts all elements of an XML file into objects.
XML Document: Words.xml
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<words>
<word>
<en>boy</en>
<ch> Boy </ch>
</word>
<word>
<en>girl</en>
<ch> Girls </ch>
</word>
<word>
<en>teacher</en>
<ch> Teacher </ch>
</word>
<word>
<en>beauty</en>
<ch> Beauty </ch>
</word>
</words>
SimpleXML Use examples:
Copy Code code as follows:
<?php
echo "<pre>";
$words = simplexml_load_file ("Words.xml")//Returns an array object that can be viewed with print_r () or Var_dump ()
Var_dump ($words);
?>
Read content:
Copy Code code as follows:
<?php
echo "<pre>";
$words = simplexml_load_file ("Words.xml")//Returns an array object that can be viewed with print_r () or Var_dump ()
Echo $words->word[2];
foreach ($words->word as $row) {//$row or an object
Print_r ($row);
echo $row->ch. " }
?>
The second section of the code output results:
Copy Code code as follows:
SimpleXMLElement Object
(
[En] => boy
[CH] => Boy
)
Boy
SimpleXMLElement Object
(
[En] => girl
[CH] => Girl
)
Girl
SimpleXMLElement Object
(
[En] => teacher
[CH] => teacher
)
Teacher
I hope this article will help you with the Php+xml program design.