TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-03-2009, 03:29 AM   #1 (permalink)
The Contributor
 
planepixel's Avatar
 
Join Date: Feb 2009
Posts: 28
Thanks: 10
planepixel is on a distinguished road
Default single quotes or double quotes in php

Hi

i am confused about which quotes to use.
PHP Code:
 $firstName "first name";
 
$secondName 'second name';

 echo 
'first name is ' $firstName '. it is good name ';
 echo 
"second name is $secondName."
which approach is good. I read that single quotes give better performance.
which one you recommend?

thanks

Last edited by planepixel : 02-03-2009 at 03:30 AM. Reason: added one more line.
planepixel is offline  
Reply With Quote
Old 02-03-2009, 04:34 AM   #2 (permalink)
The Contributor
 
Join Date: Feb 2009
Posts: 65
Thanks: 0
Krik is on a distinguished road
Default

Go with single quote better performance and when you have to echo out HTML you can keep your double quotes for your HTML.

PHP Code:
echo '<span id="myspan">' $mytext '</span>'
Also a note on the example code you game that last echo

PHP Code:
echo "second name is $secondName."
That "." may get in trouble. Better to

PHP Code:
echo 'second name is' $secondName '.'
Krik is offline  
Reply With Quote
The Following User Says Thank You to Krik For This Useful Post:
planepixel (02-03-2009)
Old 02-03-2009, 01:08 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Though don't forget that any special character beginning with a back-slash: \b (backspace), \n (line break), \t (tab), etcetera, doesn't work as expected when encapsulated with single quotes. For that to work you must break out of your single quotes:

php Code:
echo 'Put this on' . "\n";
echo '...Two lines!';
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-03-2009, 01:35 PM   #4 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

the amount of speed gained won't matter to much. Usually thats not the bottleneck. So it really comes down to which one you want to use and which one is easier in the specific case.
CoryMathews is offline  
Reply With Quote
The Following User Says Thank You to CoryMathews For This Useful Post:
planepixel (02-04-2009)
Old 02-04-2009, 01:44 AM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Actually, Cory has a point because most of the time I tend to use sprintf for readability purposes.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-04-2009, 05:48 AM   #6 (permalink)
The Contributor
 
planepixel's Avatar
 
Join Date: Feb 2009
Posts: 28
Thanks: 10
planepixel is on a distinguished road
Default

Thanks. no confusion now.
planepixel is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get PHP 5. to work? Newbie windows PHP guy DotNetTim Absolute Beginners 11 02-01-2013 11:02 AM
SQL Injection and mysql_real_escape_string Durux General 61 01-29-2013 12:20 PM
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
Differences Between Single and Double Quotes Wildhoney General 19 11-10-2007 11:37 PM


All times are GMT. The time now is 10:43 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design