We now have a youtube channel. Subscribe!

PHP Simple XML Parser

PHP Simple XML Parser

Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP Simple XML Parser.

The simple xml parser is used to parse Names, attributes, and textual contents.

Simple XML Functions

Simple xml functions are shown below -


This function accepts file path as a first parameter and its very compulsory.



This function accepts the string instead of file reference.



This xml function accepts Dom formatted xml content and then converts into simple xml.



The below example shows how to parse an XML data file -

   $data = "<?xml version = '1.0' encoding = 'UTF-8'?>
      <Course>Web Development</Course>
      <Company>Web Design Tutorialz</Company>
   $xml = simplexml_load_string($data) or die("Error: Cannot create object");



When the above code is executed, it will produce the following result -

SimpleXMLElement Object ( [Course] => Web Development [Subject] => HTML [Company] => Web Design Tutorialz [Price] => $20 )

We can also call an xml data file as shown below and it produces the same result as shown above -

   $xml = simplexml_load_file("data") or die("Error: Cannot create object");

Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP - Simple XML GET.

Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain