Jump to content

PHP w3school tuts clarifications


Recommended Posts

Hello there. This is my first post here in w3school's forum and would like to take this opportunity to say THANKS FOR EVERYTHING because you made me who I am today. :)I'm having a great time reading and trying out the tutorials but there are a couple of things that doesn't seem right or confusing in PHP.The first I noticed was the PHP do..while loop tutorial. The description says "The example below defines a loop that starts with i=1. It will then increment i with 1, and write some output. Then the condition is checked, and the loop will continue to run as long as i is less than, or equal to 5", but the output of the code was this

The number is 2The number is 3The number is 4The number is 5The number is 6
It should stop the loop when it becomes equal to 5, right? Then why did it stop at 6?Second, the XML Expat Parser in PHP is quite confusing. The case match for switch statement to execute a function for starting elements doesn't work if it's LOWERCASE. UPPERCASE works even though my tag elements in xml are lowercase.
function start($parser,$element_name,$element_attrs) { switch($element_name) { case "NOTE": echo "-- Note --<br />"; break;
Doesn't work
case "note":
Another thing, I came across at a weird problem about the "stop" or "end" function for xml_set_element_handler. I did spend lots of time just to find out myself that a function that is named end doesn't work(function end()). Am I right? Edited by AngelicOne
Link to post
Share on other sites

The reason the loop can output 6 is because the condition to enter the loop is that $i is less than or equal to 5. Inside the loop $i begins being equal to five, but then 1 is added to $i and finally $i is printed, displaying a 6 before the loop terminates.I haven't worked with the XML Expat parser, I usually use the DOMDocument class instead, so I'm not sure why element names are returned in uppercase.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...