To read an xml file in php we have 3 ways.
- SimpleXML
(in php 5 and onwards)
- Expat
Parser
- XML
DOM
I am going to show you the easiest way to process/read xml
file in php using SimpleXML.
Example with Code and Syntax:
<?xml version="1.0"
encoding="ISO-8859-1"?>
<book>
<name>PHP</name>
<price>68</price>
</book>
<?php
$xml=simplexml_load_file("book.xml");
echo $xml->name. "<br>";
echo $xml->price. "<br>";
As show in above example, I have loaded book.xml file and read the contents using simplexml_load_file function.
No comments:
Post a Comment