Welcome to the Treehouse Community
Looking to learn something new?
Beau Delfosse9,135 Points
What is the difference between ' ' and " " in PHP ? and when, where should I use it
If you know, could you maybe give me some tags where I can use them in ?
As far as basic PHP is concerned, when you're echoing out a string enclosed in " ", you can use the variable inside the string without having to concatenate. For example:
$message = "Hello $first_name! Nice to meet you!";
With single quotes, you would write that code as:
$message = "Hello " . $first_name . "! Nice to meet you!";
Also, just make sure that any string you're echoing out that uses quotation marks is using the opposite version of the enclosing marks you started off with. For instance:
$message = "<a href='index.php'>Click here to view cat videos.</a>";
If you use double quotes surrounding the index.php above, it would end the first string and cause error.
I hope these couple of examples help!
Benjamin Larson34,055 Points
Hi Beau, I just posted this same answer on a similar question, but it applies here too:
Reading the PHP manual can seem a bit cryptic if you are first learning the language, but it does have great explanations for the different types of syntax that can be used for specifying strings. There are actually 4 ways to specify strings (as of PHP 5.3.0):
- heredoc syntax
- nowdoc syntax
There are pros and cons to using each. Check it out at the PHP manual: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.single They give descriptions and examples of use for each of them.