Re: Embedding HTML Within a PHP Statement [message #175995 is a reply to message #175980] |
Mon, 14 November 2011 13:54 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma:
|
Senior Member |
|
|
On Mon, 14 Nov 2011 02:29:30 -0500, Call Me Tom wrote:
> I was under the impression that a section of PHP code (the part between
> <?PHP and ?>) was independent of any other section of PHP code. Today I
> found the following code in a working program:
Nope. All the php code in a script shares the same environment.
eg in a single file:
-----------------------------------------
<?php
// some code
?>
some html
<?php
// some more code
?>
more html
<?php
// even more code
?>
-----------------------------------------
all the php code is operating with the same variables etc.
This means you can:
<?php
if (condition) {
?>
some html
<?php
}
?>
It might not be the tidiest way to do it (using heredoc is usually
tidier), and I'm sure at least one purist will say "you shouldn't do it
like that" but it works and it's valid php.
Rgds
Denis McMahon
|
|
|