RSS

[ javascript in php ][ tip ] nested quotes

19 Oct

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.

Advertisements
 
Leave a comment

Posted by on October 19, 2011 in javascript

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: