simplexml & foreach error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ddjen11
Forum Newbie
Posts: 2
Joined: Mon Mar 07, 2005 1:08 pm

simplexml & foreach error

Post by ddjen11 »

Hi I'm just learning simplexml, got a very basic question. Using the sample codes straight from php.net: http://us3.php.net/simplexml

In Example #3, it defines $xmlstr that hold a simple xml doc & loads it:

Code: Select all

$xml = simplexml_load_string($xmlstr);
Then it echoes some content:

Code: Select all

foreach ($xml->movie as $movie) {
echo $movie->plot, '<br />';
&#125;
"foreach" is causing an error that asked the browser to be closed. It happened on 2 different pcs on bothe IE & firefox. Can anyone point out the problem? Thanks for your help.


$xmlstr is set up this way(copied from the php link above):

Code: Select all

$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>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
David


feyd | :roll:
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

1. Please edit your existing post and use the code tags.

2. Is this test page somewhere that we can view it?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

do the usual debugging routine..

ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);


i tested the script with php5.0.3 and everythings works just fine.
ddjen11
Forum Newbie
Posts: 2
Joined: Mon Mar 07, 2005 1:08 pm

Post by ddjen11 »

I am not even able to see any errors from php. I got a Windows message saying "Apache.exe has generated errors and will be closed by Windows. You need to restart the program. "

Windows2000 Professional

Apache Version Apache/2.0.52 (Win32) mod_ssl/2.0.52 OpenSSL/0.9.7e PHP/5.0.2

PHP Version 5.0.2

Simplexml support enabled
Revision $Revision: 1.139.2.4 $
Schema support enabled

Thanks.
Post Reply