Search code examples
phpquotes

Issues while using Quotes in PHP


I have Learnt that Quotes doesn't matter in PHP.

But in the following code, if I try to use single quotes in eval(); I get error, on the other hand code works fine with Double Quotes.

$a = '2';
$b = '3';
$c = '$a+$b';
echo $c.'<br/>';
eval("\$c = \"$c\";");
//eval('\$c = \'$c\';');  //Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING
echo $c;

Solution

  • PHP.net says that escape sequences are not expanded when using single quotes.