Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-24-2003, 06:06 PM   PM User | #1
mothra
Regular Coder

 
Join Date: Jul 2003
Posts: 262
Thanks: 1
Thanked 0 Times in 0 Posts
mothra is an unknown quantity at this point
Difference between " & '

I notice that " & ' are both used in php for strings and elements of arrays, etc... is there any difference? Are there situations where the use of one versus the other will cause problems?

Thanks...
mothra is offline   Reply With Quote
Old 10-24-2003, 08:34 PM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
No difference as far as I know, obviously you can't mix them though, as in $var = "blah'; but I don't know much
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 10-24-2003, 09:26 PM   PM User | #3
missing-score
Senior Coder


 
missing-score's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 2,194
Thanks: 0
Thanked 0 Times in 0 Posts
missing-score is on a distinguished road
ok, well if you want to include a variable in a string, like the example below

PHP Code:
$variable 'hello';

echo 
"Todays word is: $hello"
you MUST use double quotes to print the variable.. compare these:

PHP Code:

$variable 
'hello';

// double quotes
echo "Todays word is: $variable";
// prints Todays word is hello

//single quotes
echo 'Todays word is $variable';
// prints Todays word is $variable 
you should always use single quotes unless you are including variables in a string, becuase if you use double quotes, php will look for varibales and insert them... this makes the code slower...

so...
PHP Code:
echo 'Text Without variables in single quotes';

echo 
"Is better than text without strings in double quotes"
missing-score is offline   Reply With Quote
Old 10-25-2003, 01:10 PM   PM User | #4
mothra
Regular Coder

 
Join Date: Jul 2003
Posts: 262
Thanks: 1
Thanked 0 Times in 0 Posts
mothra is an unknown quantity at this point
That's good to know. I didn't know you could include a variable directly in a string like that. I will probably just stick with single quotes for everything unless I run into some unforeseen problem down the road.

Thanks!
mothra is offline   Reply With Quote
Old 10-25-2003, 01:15 PM   PM User | #5
missing-score
Senior Coder


 
missing-score's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 2,194
Thanks: 0
Thanked 0 Times in 0 Posts
missing-score is on a distinguished road
you know that variables can be included:

PHP Code:

$string 
'Text with '.$variable.' value';

// or even

$string "Text with ".$variable." value"
missing-score is offline   Reply With Quote
Old 10-25-2003, 07:02 PM   PM User | #6
mothra
Regular Coder

 
Join Date: Jul 2003
Posts: 262
Thanks: 1
Thanked 0 Times in 0 Posts
mothra is an unknown quantity at this point
Yes, concatenation is the way I'm accustomed to doing it. I thought it was kind of neat that variables can be placed directly in the string though.
mothra is offline   Reply With Quote
Old 10-26-2003, 01:27 PM   PM User | #7
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
Well, I'm not sure if this is the same as in C but seeing as most things in PHP are I gather it is.

In C 'string' is constant, like str[] and "string" is like char *str (const again) but 'a' will return 96 (I think) and "a" will return a ...
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline   Reply With Quote
Old 10-26-2003, 02:50 PM   PM User | #8
missing-score
Senior Coder


 
missing-score's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 2,194
Thanks: 0
Thanked 0 Times in 0 Posts
missing-score is on a distinguished road
wow, i never thought of that. Ill have to take a look. thanks.
missing-score is offline   Reply With Quote
Old 10-26-2003, 03:08 PM   PM User | #9
Acecool
New Coder

 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Acecool is an unknown quantity at this point
' is exact

echo '$hello world';
// $hello world comes out

echo "$hello world";
// world comes out (unless $hello is set)
__________________
http://www.acecoolco.com/avs/Acecool..._Signature.php
If you plan on contacting me, please read this: Legal Terms & Conditions
Acecool is offline   Reply With Quote
Old 10-26-2003, 09:14 PM   PM User | #10
SDP2006
Regular Coder

 
Join Date: May 2003
Location: 34° 54' N 82° 13' W
Posts: 996
Thanks: 0
Thanked 0 Times in 0 Posts
SDP2006 is an unknown quantity at this point
While we are sorta on the subject, what is it called when you do this
PHP Code:
$string 'Text with '.$variable.' value';

// or even

$string "Text with ".$variable." value"
The periods, that is
__________________
Stevie Peele
Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
#dev - any programming,etc. question
#design - design discussion and critque
#central - general chat
Come join us!
SDP2006 is offline   Reply With Quote
Old 10-26-2003, 09:18 PM   PM User | #11
fredmv
Regular Coder

 
Join Date: Jul 2003
Location: Massachusetts
Posts: 472
Thanks: 0
Thanked 0 Times in 0 Posts
fredmv is an unknown quantity at this point
Quote:
Originally posted by SDP2006
While we are sorta on the subject, what is it called when you do this
PHP Code:
$string 'Text with '.$variable.' value';

// or even

$string "Text with ".$variable." value"
The periods, that is
String concatenation.
__________________
Moderator @ WebDeveloper.com
Mentor @ WebXpertz.net
fredmv is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:42 AM.


Advertisement
Log in to turn off these ads.