php read xml file code example

Example 1: php read xml from url

$xml=simplexml_load_file("filename.xml") or die("Error: Cannot create object");
echo $xml->detaildata->lattitude;
echo $xml->detaildata->longitude;

Example 2: php read xml from url

$xml=simplexml_load_file("filename.xml") or die("Error: Cannot create object");
echo $xml->detaildata->lattitude; // As SimpleXMLElement Object
// ... OR ...
echo $xml->detaildata->lattitude->__toString(); // As String

Example 3: read xml file in php wordpress

$xml = simplexml_load_file('big_xml_file.xml');
foreach ($xml->element as $el) {
    echo $el->name;
}

Tags:

Php Example