PHP – Simple XML

By | October 1, 2021
PHP - Simple XML

This simple XML parser will parse the name, containing attributes and the text content within the simple XML file. These are tree-based parsers. PHP supports some of the XML functions that are described below.

  • simplexml_load_file()- this function has five parameters among which the first parameter is mandatory as it takes the file path to load the XML file.
  • simplexml_load_string()- this function also takes five parameters among which the first parameter is mandatory to pass which is the string rather than the file reference.
  • simplexml_import_dom()- this function will accept the XML content in complex DOM format and allows it to convert the complex XML into simple XML format. This function will take two parameters.


   $data = "<?xml version = '1.0' encoding = 'UTF-8'?>
   $db_xml = simplexml_load_string($data) or die("Error");


SimpleXMLElement Object ( [Subject] => Program [Content] => CS [Price] => 10 )

People are also reading:

Leave a Reply

Your email address will not be published. Required fields are marked *