Once working with js code within php echo, i got totally lost when i have (double quotes(single quotes (double quotes(single quotes)))). Its like an onion and remind me a question in my fsc-II maths books having infinite square roots. I was thinking of inventing something new other than ” and “”. so that to quote string at third level. Code like following
echo " < a href= ' # ' onclick=' alert( " 123 " ) ' >LINK</a>";
was there with syntax errors and errors like
-Error: missing ) after argument list
-unterminated string literal
Resolution:
It is then resolved by a simple back slash(\) followed by a ‘ or ” as per case.
now its like
echo " < a href= ' # ' onclick=' alert( \" 123 \" ) ' >LINK</a>";
Also something about variable within single and double quotes:
$str = 'simple text' echo '$str'; // $str echo "$str"; //simple text
Means variable within single quotes is treated as a string and variable within double quotes is treated as a variable.