top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is difference between single quotes and double quotes in php ?

0 votes
408 views
What is difference between single quotes and double quotes in php ?
posted Jun 6, 2014 by Amritpal Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

3 Answers

+1 vote

Single quoted
The simplest way to specify a string is to enclose it in single quotes. Single quote is generally faster, and everything quoted inside treated as plain string.

echo 'Start with a simple string';
echo 'String\'s apostrophe';
echo 'String with a php variable'.$name;

Double quoted
Use double quotes in PHP to avoid having to use the period to separate code in string.

echo "Start with a simple string";
echo "String's apostrophe";
echo "String with a php variable $name";

answer Jun 6, 2014 by Rahul Singh
0 votes

When string is in single quotes, php will not evaluate it . If there is a string with single quotes and if we place a variable in that it would not substitute its value in string whereas double quotes support variable expansion. If we place variable in double quotes it would substitute its value in string.
<?php $str = 1; echo '$str is a value'; // OUTPUT : $str is a value echo "$str is a value"; //OUTPUT : 1 is a value ?>

answer Jun 9, 2014 by Karamjeet Singh
0 votes

Single Quotes=>
<?php $a=3; echo '$a'; // Will not work ?>

Double Quotes =>
<?php $a=3; echo "$a"; // Will Work ?>


So with Single Quote => You can not add the identifier or variable in echo statement.
But with Double Quote => You can specify the variable. PHP can easily interpret the variable in double quote. But single quote string are faster than double quote.

answer Aug 13, 2014 by anonymous
Similar Questions
+1 vote

I run an instance of apache under OS X which I use to pass data to PHP scripts using ajax. If I have a string such as "O'Toole" (without the double-quotes), then when the string (which I pass through encodeURIComponent in the browser) arrives in the PHP script, the single-quote is prefixed with a backslash. That is, the string above becomes "O'Toole".

I want my app to run under Win7, and I observe that there, the backslash is *not* inserted. This difference is a bit irritating, especially as I am having trouble discovering which component (browser, apache, PHP) is adding the backslash. On the whole, I'd rather not have it, but I'd settle for both platforms adding it. Then at least code common to both platforms can remove it.

...