Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Basics (Retired) PHP Conditionals & Loops If / ElseIf Conditionals

Beau Delfosse
Beau Delfosse
9,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 ?

3 Answers

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 Larson
Benjamin Larson
34,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):

  • single-quoted
  • double-quoted
  • 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.

gud videos..