NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Quick PHP question

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 07-26-2005, 06:20 PM THREAD STARTER               #1 (permalink)
Senior Member
 
Ringr's Avatar
Join Date: Jul 2004
Posts: 1,383
Ringr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to behold
 



Quick PHP question


Hey guys,

I just picked up a book on PHP today.
The author does describe when to use single quotes ( ' ' ) and when to use double quotes ( " " ). Like he said to use double quotes when the variable $PHP_SELF was being used.

I'm a bit lost on it though and I was wondering if someone could help me out here on when it's a good time to use single quotes and when to use double quotes and what they should be used with.

Any help would be appreciated,
Thanks
-Andy
Ringr is offline  
Old 07-26-2005, 06:59 PM   #2 (permalink)
New Member
Join Date: Jul 2005
Posts: 5
bmsterling is an unknown quantity at this point
 



"" allows you to us multiple lines and '' does not.

U can get away with using both with out having any issues. Just depends on how you want things to look when you view the source in a browser.
__________________
*****************************
Benjamin Sterling
http://www.sterlingdesign.info
http://www.webgraphds.com
bmsterling is offline  
Old 07-26-2005, 07:22 PM   #3 (permalink)
New Member
Join Date: Sep 2003
Posts: 13
unclekyky is an unknown quantity at this point
 



double quotes parse variables.
single quotes do not
PHP Code:
<?php
????: NamePros.com http://www.namepros.com/programming/110146-quick-php-question.html
$user 
'bob'// uses single quotes because there is no variable
// hello, bob.
echo "hello, $user."// the correct method would be: echo "hello, {$user}.";
// hello, $user.
echo 'hello, $user.';
?>
if you don't need to parse a variable in a string, use single quotes. otherwise use double quotes.

http://us3.php.net/types.string
unclekyky is offline  
Old 07-27-2005, 01:44 AM THREAD STARTER               #4 (permalink)
Senior Member
 
Ringr's Avatar
Join Date: Jul 2004
Posts: 1,383
Ringr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to behold
 



Aha, that makes more sense now.

Thank you guys,
-Andy
Ringr is offline  
Old 07-27-2005, 04:53 AM   #5 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Although some people will prefer single quotes, you can still use a variable the following way

Quote:
echo 'Welcome, ' . $username;
Good luck.
__________________
WP Theme Developer
Your One-stop for Premium Magazine/CMS WordPress Themes
Deluxe Themes
Porte is offline  
Old 08-20-2005, 05:24 AM   #6 (permalink)
NamePros Regular
 
Zubair1's Avatar
Join Date: Mar 2005
Posts: 912
Zubair1 is just really niceZubair1 is just really niceZubair1 is just really niceZubair1 is just really niceZubair1 is just really nice
 


AIDS/HIV
Hi ppl,

I just wanted to know if is it possible to parse variables with single quotes cause
i tried it and both work for i think single quote don't need to be escaped in
double quote and vise versa.
__________________
Live Support : Zubair11 [at] hotmail.com
Free SEO Directory! || Free Online TV || Tech Blog
Web Design & Web Development Services || Reliable Web Hosting
Zubair1 is offline  
Old 08-20-2005, 05:35 AM   #7 (permalink)
Professional Monkey
 
Amnezia's Avatar
Join Date: Jul 2005
Location: Escaped from the zoo
Posts: 907
Amnezia has a spectacular aura aboutAmnezia has a spectacular aura about
 


Cancer Survivorship Save a Life
generally speaking you should always use double quotes with \ to escape special meaning

you can use single quotes but its messy and will cause problems in some situtations
__________________
Webmaster Words
Amnezia is offline  
Closed Thread


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 12:35 PM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 10:09 AM
Quick PHP question - fopen() and related Jeanco Programming 4 06-07-2004 09:28 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:13 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger