|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-28 06:29 UTC] asukakenji at gmail dot com
Description: ------------ There is a typo in the code example. Reproduce code: --------------- Visit: http://www.php.net/manual/en/simplexml.examples-basic.php Expected result: ---------------- In example #4, line 7, it should be: foreach ($xml->movies as $movie) { Actual result: -------------- This is shown instead (the first movie should be movies): foreach ($xml->movie as $movie) { PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 06:00:01 2026 UTC |
Adding another movie to the movies collection and then running the example works as expected. <?php $xmlstr = <<<XML <?xml version='1.0' standalone='yes'?> <movies> <movie> <title>PHP: Behind the Parser</title> <characters> <character> <name>Ms. Coder</name> <actor>Onlivia Actora</actor> </character> <character> <name>Mr. Coder</name> <actor>El ActÓr</actor> </character> </characters> <plot> So, this language. It's like, a programming language. Or is it a scripting language? All is revealed in this thrilling horror spoof of a documentary. </plot> <great-lines> <line>PHP solves all my web problems</line> </great-lines> <rating type="thumbs">7</rating> <rating type="stars">5</rating> </movie> <movie> <title>Upfront and personal</title> <characters> <character> <name>Richardo</name> <actor>Richard Quadling</actor> </character> <character> <name>Ozzer</name> <actor>Oscar Quadling</actor> </character> </characters> <plot> With only a few days to go, they get the job done. </plot> <great-lines> <line>A monkey could have done it!</line> </great-lines> <rating type="thumbs">9</rating> <rating type="stars">6</rating> </movie> </movies> XML; $xml = new SimpleXMLElement($xmlstr); /* For each <movie> node, we echo a separate <plot>. */ foreach ($xml->movie as $movie) { echo $movie->plot, PHP_EOL; } ?> outputs ... So, this language. It's like, a programming language. Or is it a scripting language? All is revealed in this thrilling horror spoof of a documentary. With only a few days to go, they get the job done.