|
Posted by Norman Peelman on 06/14/07 04:37
Jon Slaughter wrote:
> I have to output a lot of html stuff mixed with php and I'm curious if its
> better to echo the html code or stop the php parser temporarily to got into
> "html mode"? Is there any drawbacks to either method?
>
> e.g.,
>
> echo "<div class=\"someclass\">"
>
> or
>
> ?><div class="someclass"><?php
>
> (realize that this is just a simple example and is not meant to represent
> the actual code I will be writing)
>
> Thanks,
> Jon
>
>
Well, a couple things...
1) echo "<div class='someclass'>" is perfectly acceptable afaik as well
as the reverse
2) the HEREDOC format also works well, examples:
$str = <<<EOT
<HTML>
<HEAD>
<TITLE>$pagetitle</TITLE>
</HEAD>
<BODY>
...
</BODY>
</HEAD>
EOT;
or
echo works too, and variables will be resolved following the same rules
as double quoted strings.
As to what is better??? Me personally, I don't use escape characters
or do alot of string concatination at all if I can get away with it...
too hard on the eyes. I would imagine jumping in and out of the parser
to be equally hard on the eyes depending on how much you have to do it.
Again, personally, I use a template system (not Smarty) for that type of
output. Code the way things are comfortable for you but remember,
outside the parser no variables can be used.
Norm
Navigation:
[Reply to this message]
|