[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.


    <h1><a href="/">Title</a></h1>
       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.
       Complex variables can be entered using {$this->someVar} syntax

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.

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 />

Incutio Web Developer

More information about the thelist mailing list