[KLUG Members] php and quotation marks

bill bill at billtron.com
Tue Sep 27 14:26:32 EDT 2005


On Tue, 2005-09-27 at 14:00, Richard Harding wrote:

> > bill
> I'm the opposite. I much prefer to see a separation of html and
> variables. By using single quotes you're forced to use the . to
> concatenate the string and it's much easier to see where content is
> coming from than searching strings for $ that may or may not be there. 

A lot of people think that, but I almost never use the . concantenation.

echo "<P align=\"center\">The name is $myvariable.</p>";

The above line works perfect, is easier than anything else to read, and
handles variables with ease.

This is harder to read:

echo '<p align="center">' . "The name is $myvariable" . '</p>';

Or even worse

<p align="center">

<?php 

echo "The name is $myvariable";

?>

</p>

They all work, but the first is much easy to scan and modify without
screwing something up.

> Not to mention that double quotes are slower since the string is parsed
> by the php engine to check for variables. Why force the parsing when
> it's not necessary?

The parsing engine is so fast, no human notices it.  If it's slower, you
won't see it.  It is simply an unnecessary fear when displaying HTML.  

Why do it?  It's easier on the programmer and almost never generates the
sort of errors that starting with single quotes causes.  If you make
changes you just make your changes and don't have to worry about sixteen
other things that might be affected (like quotes or dots or php tags or
lions or tigers or bears (oh my!).  :-)

kind regards,

bill



More information about the Members mailing list