i

PHP Tutorial

PHP SimpleXML

Simple XML is an extension that is enabled from PHP version 5.1.2 and it provides a very simple and easy way to convert XML to an object that you can use normally inside a php.

Installation : This extension is enabled by default and you can disable it by using the below option at compile time:

--disable-simplexml

And for versions before 5.1.2, you need to use –enable-simplexml to enable this extension.

It is a built-in way to parse XML files. To use Simple XML, you can use various functions such as simplexml_load_string to read XML from a string or simplexml_load_file to read an XML file.

For example: let us create a small XML file and parse it using SimpleXML parser.

To use simplexml_load_string, we will create a variable that will have some XML data as below and we will use string function to read this variable having XML data by parsing it.