Last active
April 3, 2018 16:43
-
-
Save tablatronix/942e04076901a4c561ef47f07f40695a to your computer and use it in GitHub Desktop.
cannot print xml sub collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// why does print_r($xmlobj->node) only print the first node ? | |
$string = <<<XML | |
<breakfast_menu> | |
<food> | |
<name>Belgian Waffles</name> | |
<price>$5.95</price> | |
<description> | |
Two of our famous Belgian Waffles with plenty of real maple syrup | |
</description> | |
<calories>650</calories> | |
</food> | |
<food> | |
<name>Strawberry Belgian Waffles</name> | |
<price>$7.95</price> | |
<description> | |
Light Belgian waffles covered with strawberries and whipped cream | |
</description> | |
<calories>900</calories> | |
</food> | |
<food> | |
<name>Berry-Berry Belgian Waffles</name> | |
<price>$8.95</price> | |
<description> | |
Light Belgian waffles covered with an assortment of fresh berries and whipped cream | |
</description> | |
<calories>900</calories> | |
</food> | |
</breakfast_menu> | |
XML; | |
$xml = simplexml_load_string($string); | |
$xmlfood = $xml->food; | |
print_r(count($xmlfood)); | |
print_r("<br/>\n"); | |
print_r(gettype($xmlfood)); | |
print_r("<br/>\n"); | |
// prints entire xml | |
# print_r($xmlfood); | |
# print_r("<br/>\n"); | |
// prints only 1 node | |
print_r($xmlfood); | |
print_r("<br/>\n"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment