Section 4.15. Mixed-Mode Processing


4.15. Mixed-Mode Processing

A key concept in PHP is that you can toggle PHP parsing mode whenever and as often as you want, even inside a code block. Here is a basic PHP script:

     <?php             if ($logged_in =  = true) {                     print "Lots of stuff here";                     print "Lots of stuff here";                     print "Lots of stuff here";                     print "Lots of stuff here";                     print "Lots of stuff here";             }     ?>

As you can see, there are a lot of print statements that will only be executed if the variable $logged_in is true. All the output is encapsulated into print statements, but PHP allows you to exit the PHP code island while still keeping the if statement code block openhere's how that looks:

     <?php             if ($logged_in =  = true) {     ?>             Lots of stuff here             Lots of stuff here             Lots of stuff here             Lots of stuff here             Lots of stuff here     <?php             }     ?>

The Lots of stuff here lines are still only sent to output if $logged_in is true, but we exit PHP mode to print it out. We then reenter PHP mode to close the if statement and continueit makes the whole script easier to read.



PHP in a Nutshell
Ubuntu Unleashed
ISBN: 596100671
EAN: 2147483647
Year: 2003
Pages: 249

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net