simplexml_load_file () returns an object.
Look at the structure with var_dump ($ xml):
object(SimpleXMLElement)#1 (2) { ["name"]=> string(9) "Project 1" ["features"]=> object(SimpleXMLElement)#2 (1) { ["feature"]=> array(4) { [0]=> string(9) "Feature 1" [1]=> string(9) "Feature 2" [2]=> string(9) "Feature 3" [3]=> string(9) "Feature 4" } } }
So, the code is as follows:
<?PHP $xml = simplexml_load_file('test.xml'); echo $xml->name . "\n"; foreach($xml->features->feature as $f){ echo "\t$f\n"; }
It will be displayed as:
Project 1 Feature 1 Feature 2 Feature 3 Feature 4
This is what I assume that you are after, more or less.
source share