<?php
$string = <<<XML
<a>
<foo name="one" game="lonely">1</foo>
<foo name="two" game="wow">2</foo>
</a>
XML;
$xml = simplexml_load_string($string);
var_dump($xml->foo);exit;
$xml = simplexml_load_string($string);
foreach($xml->foo->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";
}
?>
- Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.16, 7.3.18 - 7.3.33, 7.4.0 - 7.4.4, 7.4.6 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- object(SimpleXMLElement)#2 (3) {
["@attributes"]=>
array(2) {
["name"]=>
string(3) "one"
["game"]=>
string(6) "lonely"
}
[0]=>
string(1) "1"
[1]=>
string(1) "2"
}
- Output for 7.3.17, 7.4.5
- object(SimpleXMLElement)#2 (3) {
["@attributes"]=>
array(2) {
["name"]=>
string(3) "one"
["game"]=>
string(6) "lonely"
}
[0]=>
object(SimpleXMLElement)#4 (2) {
["@attributes"]=>
array(2) {
["name"]=>
string(3) "one"
["game"]=>
string(6) "lonely"
}
[0]=>
string(1) "1"
}
[1]=>
object(SimpleXMLElement)#5 (2) {
["@attributes"]=>
array(2) {
["name"]=>
string(3) "two"
["game"]=>
string(3) "wow"
}
[0]=>
string(1) "2"
}
}
preferences:
199.03 ms | 402 KiB | 294 Q