Articles in Basics Category

Usage of Quotes

In PHP, single and double quotes are used to enclose strings. Following code would throw a PHP error since the string hasn’t been enclosed by quotes.

$name = Robin Jackman;

It has to be enclosed by quotes like below.

$name = 'Robin Jackman';

While both single and double quotes can be used to enclose strings, there is a difference in how PHP interprets two methods. If you used double quotes then PHP would interpret variables and special characters (\t, \n etc) inside the string but if you used single quotes PHP would consider only the literal value of the whole string.

$name = 'Robin Jackman';
echo "Name is $name"; // Would print Name is Robin Jackman
echo 'Name is $name'; // Would print Name is $name

Usually single quotes are used when the whole statement is a simple string (like ‘Name is Robin Jackman’) and double quotes are used when the statement contains variables to be interpreted (like “Name is $name”).

Where to Head from Here...
Share with Your Peers...

We Value Your Feedback...

We love to hear what you think about this article. Please provide your opinion, suggestions and improvements using following form. Note that submitted feedback is not displayed but we will get back to you if it needs a reply.