That style is also the one I use. It works well, it is clean, and it is straightforward.

Joachim

Richard Baskett wrote:
on 10/24/03 0:47, Nathan Taylor at [EMAIL PROTECTED] wrote:


I am a recent fan of the single-quotes.  I used to use double only but when
some gurus told me the disadvantages I converted my entire project over to
single quotes.  Single quotes are ideal because as far coding goes it greatly
decreases the time of development when you don't have to worry about dropping
in the escape character on your HTML values, etc.  Granted, single quotes can
be a nuisance in some instances (like when you need a new line character) but
of course there is a way around.  I simply define a constant and call that at
the end of every line in order to substitute for the new line character.

Horizontal Tab - define("T", chr(9));
New Line - define("NL", chr(10));

Cheers,
Nathan
----- Original Message -----
From: Robert Cummings
To: Shawn McKenzie
Cc: PHP-General Sent: Thursday, October 23, 2003 10:30 PM
Subject: Re: [PHP] Code optimization: single vs. double quotes?



On Thu, 2003-10-23 at 20:43, Shawn McKenzie wrote:


I came across this post and was hoping to get a gurus opinion on the
validity.  TIA

-Shawn

I remember reading somewhere re: PHP coding that it is a better coding
practice to use single quotes as much as possible vs. using double quotes in
scripts. When using double quotes, you are forcing PHP to look for variables
within them, even though there may not be any, thus slowing execution
time...

For example it is better to code:
     Code:
     echo '<td bgcolor="'.$bgcolor2.'">&nbsp;</td></tr>';

vs.
     Code:
     echo "<td bgcolor=\"$bgcolor2\">&nbsp;</td></tr>";

Better is a very subjective question; however, style 1 will run faster since it won't look for variable interpolation. Personally I always use style 1 unless I specifically need variable interpolation or one of the special characters such as a newline. Also when doing HTML the double quotes fit nicely in the the single quote paradigm. On the other hand when I do SQL queries, I often allow interpolation just because it is more readable and because I usually use single quotes to wrap strings in my queries.


Now what is wrong with doing this?

echo '<td bgcolor="white">&nbsp;</td>'."\r\n";

That way you can still use your single quotes and still being able to use
the \r\n.. that does work doesnąt it?  Im pretty sure I have used it
before..

Anyways I guess the point is that you are not forced to use double quotes
for the full echo just so you can use the special newline characters..

Rick

"Freedom and immorality can not co-exist because freedom requires personal
responsibility." - Unknown

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to