Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- SimpleXML: accessing singular subnode as array --EXTENSIONS-- simplexml --FILE-- ..

Decoded Output download

--TEST--
SimpleXML: accessing singular subnode as array
--EXTENSIONS--
simplexml
--FILE--
<?php
$xml =<<<EOF
<people>
   <person name="Joe"></person>
</people>
EOF;

$xml2 =<<<EOF
<people>
   <person name="Joe"></person>
   <person name="Boe"></person>
</people>
EOF;

$people = simplexml_load_string($xml);
var_dump($people->person['name']);
var_dump($people->person[0]['name']);
//$people->person['name'] = "XXX";
//var_dump($people->person['name']);
//var_dump($people->person[0]['name']);
//$people->person[0]['name'] = "YYY";
//var_dump($people->person['name']);
//var_dump($people->person[0]['name']);
//unset($people->person[0]['name']);
//var_dump($people->person['name']);
//var_dump($people->person[0]['name']);
//var_dump(isset($people->person['name']));
//var_dump(isset($people->person[0]['name']));
$people = simplexml_load_string($xml2);
var_dump($people->person[0]['name']);
var_dump($people->person[1]['name']);
?>
--EXPECTF--
object(SimpleXMLElement)#%d (1) {
  [0]=>
  string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
  [0]=>
  string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
  [0]=>
  string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
  [0]=>
  string(3) "Boe"
}

Did this file decode correctly?

Original Code

--TEST--
SimpleXML: accessing singular subnode as array
--EXTENSIONS--
simplexml
--FILE--
<?php
$xml =<<<EOF
<people>
   <person name="Joe"></person>
</people>
EOF;

$xml2 =<<<EOF
<people>
   <person name="Joe"></person>
   <person name="Boe"></person>
</people>
EOF;

$people = simplexml_load_string($xml);
var_dump($people->person['name']);
var_dump($people->person[0]['name']);
//$people->person['name'] = "XXX";
//var_dump($people->person['name']);
//var_dump($people->person[0]['name']);
//$people->person[0]['name'] = "YYY";
//var_dump($people->person['name']);
//var_dump($people->person[0]['name']);
//unset($people->person[0]['name']);
//var_dump($people->person['name']);
//var_dump($people->person[0]['name']);
//var_dump(isset($people->person['name']));
//var_dump(isset($people->person[0]['name']));
$people = simplexml_load_string($xml2);
var_dump($people->person[0]['name']);
var_dump($people->person[1]['name']);
?>
--EXPECTF--
object(SimpleXMLElement)#%d (1) {
  [0]=>
  string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
  [0]=>
  string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
  [0]=>
  string(3) "Joe"
}
object(SimpleXMLElement)#%d (1) {
  [0]=>
  string(3) "Boe"
}

Function Calls

simplexml_load_string 1

Variables

$xml <people> <person name="Joe"></person> </people>
$xml2 <people> <person name="Joe"></person> <person name="Bo..

Stats

MD5 d4e186abf29ed0ba109bab5564fc2b31
Eval Count 0
Decode Time 85 ms