1
<playerstats>
 <stats>
  <stat>
   <name>total_kills</name>
   <value>9999</value>
  </stat>
  <stat>
   <name>total_deaths</name>
   <value>1234</value>
  </stat>
 </stats>
</playerstats>

How do I search for "total_kills" to get the value "9999" using simplexml in php?

1 Answers1

1

You could make use of simplexml_load_string in PHP.

<?php
$xml='<playerstats>
 <stats>
  <stat>
   <name>total_kills</name>
   <value>9999</value>
  </stat>
  <stat>
   <name>total_deaths</name>
   <value>1234</value>
  </stat>
 </stats>
</playerstats>';
$xml = simplexml_load_string($xml);
foreach ($xml->stats->stat as $child)
{
 if($child->name=='total_kills')
 {
     echo $child->value;
 }
}

OUTPUT :

9999
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126