Re: Re: newbie question - php parsing
| From: | Sebastiano Pomata | Date: | Thu, 23 Jul 2009 09:25:51 +0000 |
| Subject: | Re: Re: newbie question - php parsing | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-295733@lists.php.net to get a copy of this message | ||
Thanks, it's now much more clear. I thought that html parts outside
php tags were just dumped to output, no matter of if-else statements
and other conditions. I was *definitely* wrong
2009/7/23 Peter Ford <pete@justcroft.com>:
> In response to Sebastiano:
>
> There would be not much point in using something like PHP if it ignored the "if"
> statements in the code!
> What effectively happens in a PHP source file is that all the bits outside of
> the <?php ?> tags are treated like an "echo" statement (except that it handles
> quotes and stuff nicely)
>
> Your original code:
>
> <?php if (the_title('','',FALSE) != 'Home') { ?>
> <h2 class="entry-header"><?php the_title(); ?></h2>
> <?php } ?>
>
> can be read like:
>
> <?php
> if (the_title('','',FALSE) != 'Home') {
> echo '<h2 class="entry-header">';
> the_title();
> echo '</h2>';
> }
> ?>
>
> You might even find a small (but probably really, really, really small)
> performance improvement if you wrote it that way, especially if it was in some
> kind of loop.
> Note that I prefer to keep HTML separate from PHP as much as possible because it
> helps me to read it and helps my editor check my syntax and HTML structure better...
>
>
> --
> Peter Ford phone: 01580 893333
> Developer fax: 01580 893399
> Justcroft International Ltd., Staplehurst, Kent