note 99083 added to language.basic-syntax.phpmode
| From: | quickfur at quickfur dot ath dot cx | Date: | Mon, 26 Jul 2010 21:40:16 +0000 |
| Subject: | note 99083 added to language.basic-syntax.phpmode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171147@lists.php.net to get a copy of this message | ||
When the documentation says that the PHP parser ignores everything outside the <?php ... ?>
tags, it means literally EVERYTHING. Including things you normally wouldn't consider
"valid", such as the following:
<html><body>
<p<?php if ($highlight): ?> class="highlight"<?php endif;?>>This is a
paragraph.</p>
</body></html>
Notice how the PHP code is embedded in the middle of an HTML opening tag. The PHP parser
doesn't care that it's in the middle of an opening tag, and doesn't require that it
be closed. It also doesn't care that after the closing ?> tag is the end of the HTML opening
tag. So, if $highlight is true, then the output will be:
<html><body>
<p class="highlight">This is a paragraph.</p>
</body></html>
Otherwise, it will be:
<html><body>
<p>This is a paragraph.</p>
</body></html>
Using this method, you can have HTML tags with optional attributes, depending on some PHP condition.
Extremely flexible and useful!
----
Server IP: 69.147.83.197
Probable Submitter: 208.91.114.4
----
Manual Page -- http://www.php.net/manual/en/language.basic-syntax.phpmode.php
Edit -- https://master.php.net/note/edit/99083
Del: integrated -- https://master.php.net/note/delete/99083/integrated
Del: useless -- https://master.php.net/note/delete/99083/useless
Del: bad code -- https://master.php.net/note/delete/99083/bad+code
Del: spam -- https://master.php.net/note/delete/99083/spam
Del: non-english -- https://master.php.net/note/delete/99083/non-english
Del: in docs -- https://master.php.net/note/delete/99083/in+docs
Del: other reasons-- https://master.php.net/note/delete/99083
Reject -- https://master.php.net/note/reject/99083
Search -- https://master.php.net/manage/user-notes.php