[thelist] PHP inside or outside?

Richard Harb rharb at earthling.net
Sat Apr 24 13:40:01 CDT 2004


I agree with some people giving feedback before that you should do
whatever you prefer: the difference in speed is negligable: if you
feel you are better and faster at maintaining code doing it one way,
by all means do it!

I just wanted to point out that there is another way of assembling
those echo statements:

echo '<a class="lightright" href="description_view.php?idc_ref=' .
$parent_ref . '" title="go back">Back to Description</a>';

The advantage I see is that it's pretty clear to read, and it 'might'
give you a speed improvement as well as the parser does not need to
evaluate the string within the single quotes.

Your choice

Richard


Saturday, April 24, 2004, 8:06:59 PM, you wrote:

> At 14:28 on Saturday, 24 Apr 2004, Richard Davey wrote:

>> Hello Tony,
>>
>> Saturday, April 24, 2004, 1:00:23 PM, you wrote:
>>
>> TC> I also find it easier to read  echo'd php variables within html than
>> to
>> TC> read echo'd html within PHP
>> TC> (all those escaped characters - makes it look really untidy.)
>>
>> I'd have to disagree on this one for the simple fact that if you're
>> writing XHTML compliant code, you need to quote everything - and if
>> you're injecting variables into your echo statement, you then need to
>> escape all of the quotes which can lead to lots of parser errors IMHO.
>>
>> (or you echo with single quotes and then cannot use variables inline,
>> so have to break out, concat them, etc.. quite messy too).
>>
>> The more times you swap in and out of HTML/PHP, the more work the PHP
>> parser has to do - but to be honest I bet the speed difference in this
>> regard is absolutely tiny, so it's best to treat this one as a "do
>> whatever suits you" situation.


> what I meant was that this:

> echo "<a class=\"lightright\"  
> href=\"description_view.php?idc_ref=$parent_ref\" title=\"go back\" >Back
> to Description</a>";

> is harder (for me) to read than this:

> <a class="lightright" href="description_view.php?idc_ref=<? echo  
$parent_ref;?>>" title="go back">back to description</a>

> especially when the page is mostly xhtml with a few bits of PHP logic.

> mostly because each quoted attribute needs escaping and I have a habit of
> forgetting and then the PHP fails.

> as you say - "whatever suits you"

> ;o)




More information about the thelist mailing list