PHP string data types are created by placing text in single quotes (literal) or double quotes.

PHP Strings

PHP string data types are created by placing text in single quotes (literal) or double quotes. The word "string" comes from "letters stringed together to make up words"

Single vs Double Quotes

Let's look at a quick example to see what the difference between double and single quotes is

$website = 'clevertechie.com'; //string data type $double = "Hello my web site is called $website"; //output: Hello my web site is called clevertechie.com $single = 'Hello my web site is called $website'; //output: Hello my web site is called $website

As you can see the value of the variable was shown in the output for double quotes, just like expected. A proper way to say this is: "a variable has been expanded" according to php.net. However, when using single quotes, the text $website was in the output, which is the literal variable name, hence single quotes are also called literal quotes, because they will interpret any text within literally.

It's a good practice to use single quotes whenever you're sure that you won't be using any variable names within the string.

String Delimiters

If you're going to use a single quote character within single quotes, it must be escaped with a backslash delimiter ( \ )

$message = 'I think we\'re going to make a great team!'; //output: I think we're going to make a great team!

And if we wanted to print the backslash inside single quotes, we would escape it as well, creating a double backslash ( \\ ).

$message = 'Are you sure you want to wipe out C:\\localhost\\clevertechie.com?'; //output: Are you sure you want to wipe out C:\localhost\clevertechie.com?