Saturday February 11, 2012 @ 11:11:07 GMT+10    ( Weather:  n/a )
Home » Weblog Archives

Powered byD's Bloggie
Weblog » Archive » 2005 » September » Day 30 » PHP Single Quote vs Doubel Quote
Browse by specific entry ...
 PHP register_globalsPHP urldecode() 

PHP Single Quote vs Doubel Quote - 7:24 pm
Coding , PHP  -  poster 

What's the differences between a ' (single quote) and " (double quote) in PHP programming ? They act quite the same. However, for double quotes, PHP checks the contents for a variable to interpolate and escape characters like the \n newline. This makes your scripts SLOWER. It's doesn't really matters if you're writing a small script, but it will help PHP parse faster in a larger script.

Consider the following:
[ Hide ]
[ Highlight ] [ Text ]
$name = 'Darren'; // This one's better
$name = "Darren";


That doesn't mean that double quotes are useless. It helps on readability in some situations:
[ Hide ]
[ Highlight ] [ Text ]
echo '<a href="' . $url . '">' . $text . '</a>';
echo "<a href=\"$url\">$text</a>";
// You cannot do a \n with single quote
echo "\nThis is a new line\n";


Using ' or " ? You should know which to use next time.
 PHP register_globalsPHP urldecode() 

Reader comments ( Add your comments )

- No comments (yet) -

Leave a public comment

Info Note: Neither BBCode nor HTML tags are supported currently.
Why ? Just to make my life easier and keep things simple.
Others: Comments that are longer than 1000 characters will be truncated.

    ) Info

Info

Info


Before you submit... verification

Please enter verification codes as seen in the image above to post your comment.
If you can't read the word, click here
(Your comment will be manually approved by admin before it's displayed to public)

$ view_blog.php 2009.09.17 18:16:41 $
Lost? | XML/HTML sitemap | Contact
38.107.179.240 , 22 queries , 0.0604s
Gzip enabled , CSS compressed , JS compressed
Copyright © 2005-2011 Darren's Outpost