This article mainly introduces the application of SimpleXML in php + xml programming. The example shows how SimpleXML functions operate XML files. For more information, see
This article mainly introduces the application of SimpleXML in php + xml programming. The example shows how SimpleXML functions operate XML files. For more information, see
This article describes the application of SimpleXML in php + xml programming. Share it with you for your reference. The details are as follows:
SimpleXML's core idea is to operate xml files in an object-oriented manner, which converts all elements of the xml file into objects.
Xml document: words. xml
The Code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
Boy
Boy
Girl
Girl
Teacher
Instructor
Beauty
Beauty
Simplexml example:
The Code is as follows:
<? Php
Echo"
";
$ Words = simplexml_load_file ("words. xml"); // returns an array object, which can be viewed using print_r () or var_dump ().
Var_dump ($ words );
?>Read content:
The Code is as follows:
<? Php
Echo"
";
$ Words = simplexml_load_file ("words. xml"); // returns an array object, which can be viewed using print_r () or var_dump ().
// Echo $ words-> word [2];
Foreach ($ words-> word as $ row) {// $ row is still an object
Print_r ($ row );
Echo $ row-> ch. ""; // In fact, $ row-> ch is still an object, but it cannot be echo
}
?>
Output result of the second code:
The Code is as follows:
SimpleXMLElement Object
(
[En] => boy
[Ch] => boy
)
Boy
SimpleXMLElement Object
(
[En] => girl
[Ch] => girl
)
Girl
SimpleXMLElement Object
(
[En] => teacher
[Ch] => instructor
)
Instructor
I hope this article will help you with php + xml programming.