The previous article introduced you to "Do you know what XML Expat is? How does he define it? 》, this article continues to introduce to you. Regarding the understanding of XML SimpleXML, I believe you will definitely make new discoveries and gains. Come on, let’s explore together!
SimpleXML is a new feature in PHP 5.
Reading/extracting data from XML files/strings
Editing text nodes or attributesHowever, when dealing with advanced XML, such as namespaces, it is best to use the Expat parser or XML DOM.Installation:
Starting with PHP 5, SimpleXML functions are an integral part of PHP core. No installation is required to use these functions.
PHP SimpleXML Example: Suppose we have the following XML file, "note.xml":<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
<?php $xml=simplexml_load_file("note.xml"); print_r($xml); ?>
Output the data of each element in the XML file:
<?php $xml=simplexml_load_file("note.xml"); echo $xml->to . "<br>"; echo $xml->from . "<br>"; echo $xml->heading . "<br>"; echo $xml->body; ?>
Recommended study: "PHP Video Tutorial
"The above is the detailed content of What is PHP SimpleXML? If you are a fan of PHP, come in and take a look!. For more information, please follow other related articles on the PHP Chinese website!