note 121784 deleted from simplexml.examples-basic by cmb
| From: | cmb@php.net | Date: | Wed, 08 Jun 2022 16:28:42 +0000 |
| Subject: | note 121784 deleted from simplexml.examples-basic by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218566@lists.php.net to get a copy of this message | ||
Note Submitter: dianarusu21 at gmail dot com
----
Quick start with xml.
//PHP file:
<?php
$xml = simplexml_load_file("simpleXml.xml");
foreach ($xml as $key => $value) {
foreach ($value as $key => $value) {
echo $key.": ".$value."</br>";
}
}
?>
//XML file:
<?xml version="1.0" encoding="UTF-8"?>
<locations>
<country>
<name>Romania</name>
<capital>Bucharest</capital>
<language>Romanian</language>
</country>
<country>
<name>Frace</name>
<capital>Paris</capital>
<language>France</language>
</country>
<country>
<name>Spain</name>
<capital>Madrid</capital>
<language>Spanish</language>
</country>
</locations>
//Output:
// name: Romania
// capital: Bucharest
// language: Romanian
// name: Frace
// capital: Paris
// language: France
// name: Spain
// capital: Madrid
// language: Spanish
NOTE: You don't need to include the xml file in the php file..