Posted by Chung Leong on 01/12/06 05:23
Domestos wrote:
> Hi all,
>
> I was wondering if there is a standard when mixing PHP and HTML script on a
> page... and if there were any articles on this subject...
Not really. That's one nice thing about PHP--there is no orthodoxy.
> for example... which is better or more standard....
>
> <html>
> <head>
> <title>title text</title>
> </head>
> <body>
> You name is <?php $name?>
> </body>
> </html>
That's the style I prefer. Echo HTML from PHP becoming a huge pain when
the page makes use of Javascript. Instead of plain-o echo, I usually
use a function with a short name, as almost nearly everything output
needs to be escaped for HTML special characters.
Example:
function P($s, $flags = 0) {
$s = htmlspecialchars($s);
if(!($flags & NO_BR_TAGS)) {
$s = nl2br($s);
}
echo $s;
}
Then scatter throughout my HTML:
.....
<tr><td><a href="<? P($url) ?>"><? P($title) ?></a></td></tr>
....
[Back to original message]
|