PHP Scripting

Read XML File

Read XML file using PHP simplexml_load_file

6/28/2020
0 views
read-xml-file.phpPHP
<?php
	/*  Interprets an XML file into an object */
	$xml = simplexml_load_file('customers.xml');
	
	/* Runs XPath query on XML data */
	foreach($xml->xpath("customer") as $customer) {
		
		/* Print XML data */
		echo "Customer Name: ".$customer->name."<br />";
		echo "Customer Name: ".$customer->email."<br />";
		echo "Customer Name: ".$customer->requirement."<br /><br />";
	}
?>



/* Output */
Customer Name: James
Customer Name: james@gmail.com
Customer Name: Website

Customer Name: Jonny
Customer Name: jonny@gmail.com
Customer Name: Android App
PHPread XML file using PHPsimple xmlxpath

Related Examples