Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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..