parsing XML file in PHP easiest way -


i'm searching easiest way values xml file using php.

<?xml version="1.0" encoding="utf-8"?> <oscam version="1.20-unstable_svn build r10649"   revision="10649" starttime="2015-05-27t06:41:07-0400" uptime="710700" readonly="0"> <reader label="sky" status="off" caid="09c7">     <emmstats totalwritten="0" totalskipped="0" totalblocked="0" totalerror="0">         <emm type="unknown" result="error">0</emm>         <emm type="unique" result="error">0</emm>         <emm type="shared" result="error">0</emm>         <emm type="global" result="error">0</emm>         <emm type="unknown" result="written">0</emm>         <emm type="unique" result="written">0</emm>         <emm type="shared" result="written">0</emm>         <emm type="global" result="written">0</emm>         <emm type="unknown" result="skipped">0</emm>         <emm type="unique" result="skipped">0</emm>         <emm type="shared" result="skipped">0</emm>         <emm type="global" result="skipped">0</emm>         <emm type="unknown" result="blocked">0</emm>         <emm type="unique" result="blocked">0</emm>         <emm type="shared" result="blocked">0</emm>         <emm type="global" result="blocked">0</emm>      </emmstats>     <ecmstats count="0" totalecm="0" lastaccess="">      </ecmstats>     <ecmhistory></ecmhistory>   </reader> </oscam> 

for example need "uptime" , "status" field. tried:

$oscam = simplexml_load_file('data.xml'); $uptime = (int) $oscam['uptime'];  $status = (string) $oscam->reader['status'];  echo $status; 

as commenters said, there few possibilities. simplexml - name says - imho simple one, requested in question.

it's quite easy then. assuming, xml data contained in string variable $xml:

$oscam = simplexml_load_string($xml); $uptime = (int) $oscam['uptime']; $status = (string) $oscam->reader['status']; 

now, $uptime holds value 710700 , $status holds off.

whenever confused, can try print_r($oscam) find out, how xml mapped $oscam object , hence find data need.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -