[thelist] PHP inside or outside?
Richard Livsey
richard at livsey.org
Sat Apr 24 20:19:56 CDT 2004
Marek Kilimajer wrote:
> Another thing I would note that php inside html tends to output
> nicer html output.
>
> That said, I'm fan of php inside html. :-)
If you want nicer output (and also better readability), then you can use
the heredoc syntax.
http://www.php.net/types.string
Eg:
$html=<<<EOD
<div>
<h1><a href="/">Title</a></h1>
<p>
This is some content nicely formatted. <br />
We dont have to bother about escaping ' or " in here <br />
Plus everything comes out as typed, all tabs etc all preserved.
</p>
<p>
Complex variables can be entered using {$this->someVar} syntax
</p>
</div>
EOD;
Personally I'm a fan of jumping out of PHP as little as possible and use
templates (http://smarty.php.net) for anything involving substantial
amounts of HTML.
<rant>
I'm amazed at the amount of PHP I have seen which has the following
style of code:
$html = "<a href=\"/\">this is a link - $var</a>\n";
$html .="<p>Some more text</p>\n";
$htmp .="<p id=\"x\"><a href=\"/asdf.htm\" class=\"woo\"$var2 </p>\n";
Which could be much better replaced by a heredoc style bit of code which
would increase readability, output, speed (taking out all the string
concatenations), ease of coding (if you miss one \" you have a bug)....
<rant />
--
R.Livsey
Incutio Web Developer
www.livsey.org
www.incutio.com
More information about the thelist
mailing list