read xml string in php 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: xml to object php

$object = json_decode(json_encode(simplexml_load_string($xml)));

Example 3: 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

Tags:

Php Example