mothra
10-24-2003, 06:06 PM
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...
Thanks...
|
||||
Difference between " & 'mothra 10-24-2003, 06:06 PM 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... Nightfire 10-24-2003, 08:34 PM No difference as far as I know, obviously you can't mix them though, as in $var = "blah'; but I don't know much :p missing-score 10-24-2003, 09:26 PM ok, well if you want to include a variable in a string, like the example below $variable = 'hello'; echo "Todays word is: $hello"; you MUST use double quotes to print the variable.. compare these: $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... echo 'Text Without variables in single quotes'; echo "Is better than text without strings in double quotes"; mothra 10-25-2003, 01:10 PM 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! missing-score 10-25-2003, 01:15 PM you know that variables can be included: $string = 'Text with '.$variable.' value'; // or even $string = "Text with ".$variable." value"; mothra 10-25-2003, 07:02 PM 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. Mhtml 10-26-2003, 01:27 PM 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 ... missing-score 10-26-2003, 02:50 PM wow, i never thought of that. Ill have to take a look. thanks. Acecool 10-26-2003, 03:08 PM ' is exact echo '$hello world'; // $hello world comes out echo "$hello world"; // world comes out (unless $hello is set) SDP2006 10-26-2003, 09:14 PM While we are sorta on the subject, what is it called when you do this $string = 'Text with '.$variable.' value'; // or even $string = "Text with ".$variable." value"; The periods, that is fredmv 10-26-2003, 09:18 PM Originally posted by SDP2006 While we are sorta on the subject, what is it called when you do this $string = 'Text with '.$variable.' value'; // or even $string = "Text with ".$variable." value"; The periods, that is String concatenation. |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum