Home > Backend Development > PHP Tutorial > SimpleXML application examples of php+xml programming, simplexml application examples_PHP tutorial

SimpleXML application examples of php+xml programming, simplexml application examples_PHP tutorial

WBOY
Release: 2016-07-13 10:09:06
Original
737 people have browsed it

SimpleXML application examples of php+xml programming, simplexml application examples

The example in this article describes the application of SimpleXML in php+xml programming. Share it with everyone for your reference. The details are as follows:

The core idea of ​​SimpleXML: to operate xml files in an object-oriented manner, it will convert all elements of the xml file into objects.

xml document: words.xml

Copy code The code is as follows:



boy
Boy


girl
Girl


teacher
Teacher


beauty
Beauty


simplexml usage example:
Copy code The code is as follows:
echo "
";
$words = simplexml_load_file("words.xml");//Returns an array object, which can be viewed with print_r() or var_dump()
var_dump($words);
?>

Read content:

Copy code The code is as follows:
echo "
";
$words = simplexml_load_file("words.xml");//Returns an array object, which can be viewed with 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."
"; //Actually, $row->ch is still an object, it can only be echoed out
}
?>

The second code output result:
Copy 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] => Teacher
)
Teacher

I hope this article will be helpful to everyone’s php+xml program design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/947220.htmlTechArticleApplication examples of SimpleXML in php+xml programming, simplexml application examples. This article describes the application examples of SimpleXML in php+xml programming. application. Share it with everyone for your reference. The details are as follows: SimpleXM...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template