<?php
$xml = "<root>
<parent>
<child name='Child1' />
<child name='Child2' />
<subparent>
<child name='Child3' />
</subparent>
</parent>
<child name='Child4' />
</root>";
$xml = simplexml_load_string( $xml);
foreach( $xml->xpath( '//child') as $child) {
echo $child->attributes()['name'] . "\n";
}
- Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.1 - 5.6.8, 5.6.10, 5.6.12 - 5.6.29, 5.6.31, 5.6.35 - 5.6.40, 7.0.1 - 7.0.2, 7.0.6 - 7.0.9, 7.0.11, 7.0.13 - 7.0.23, 7.0.25 - 7.0.33, 7.1.0, 7.1.3, 7.1.6 - 7.1.10, 7.1.12 - 7.1.16, 7.1.21 - 7.1.33, 7.2.0 - 7.2.4, 7.2.6 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1, 8.1.28, 8.2.16 - 8.2.18, 8.3.3 - 8.3.6
- Child1
Child2
Child3
Child4
- Output for 5.6.0, 5.6.9, 5.6.11, 5.6.30, 5.6.32 - 5.6.34, 7.0.0, 7.0.3 - 7.0.5, 7.0.10, 7.0.12, 7.0.24, 7.1.1 - 7.1.2, 7.1.4 - 7.1.5, 7.1.11, 7.1.17 - 7.1.20, 7.2.5
Process exited with code 137.- Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected '[', expecting ',' or ';' in /in/h2jIX on line 16
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected '[', expecting ',' or ';' in /in/h2jIX on line 16
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error, expecting `','' or `';'' in /in/h2jIX on line 16
Process exited with code 255.
preferences:
215.9 ms | 401 KiB | 331 Q