[thelist] PHP inside or outside?

Diane Soini dianesoini at earthlink.net
Sun Apr 25 21:02:02 CDT 2004


I agree. If I can get nearly all the html out of the php and into a 
template then I'm happy. It's much easier to redesign the site. I've 
done something similar with JSP and Apache SSI.

Thanks for the heredoc tip. I didn't know php could do that (I'm a php 
novice.) I always use that whenever possible with perl. It is so much 
better than all that escaped code stuff, especially if you have to 
include some javascript!

I must admit a line here or there of ugly escaped html is ok by me as 
long as there is no presentation stuff like lots of css class 
attributes and whatnot.


On Sunday, April 25, 2004, at 04:10 AM, thelist-request at lists.evolt.org 
wrote:

> Subject: Re: [thelist] PHP inside or outside?
> Reply-To: "thelist at lists.evolt.org" <thelist at lists.evolt.org>
>
>
> 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
***
Don't be afraid to try something new. An amateur built the ark. 
Professionals built the Titanic. -unknown



More information about the thelist mailing list