开发者

Syntax problem with quotes in PHP and HTML

I have this php code

开发者_开发百科
echo "<textarea id='textarea' cols='70' rows='5' name='code'>".$code."</textarea>";

and I need to put this onClick="SelectAll('txtarea');" after id='textarea' but the quotes are messing me up and I cant figure it out.

Any help?

Thanks!


Explaination

You will need to escape the double quotes, so they will not be read as PHP code. You can do this by typing a \ character before them. You can read more about escaping characters in PHP here.


Edit your code to this

echo "<textarea id='textarea' onClick=\"SelectAll('txtarea');\" cols='70' rows='5' name='code'>".$code."</textarea>";


Try this: echo "<textarea id='textarea' onClick=\"SelectAll('txtarea');\" cols='70' rows='5' name='code'>".$code."</textarea>";


You can escape quotes with the backslash char "\". Try something like that:

echo "<textarea id=\"textarea\"></textarea>";


Did you try use Escape Character \" ?

So it would be

onClick=\"SelectAll('txtarea');\"


echo "<textarea id='textarea' onClick='SelectAll(\"txtarea\");' cols='70' rows='5' name='code'>".$code."</textarea>";


Use \" instead of " within your text.


Use this

echo "<textarea id='textarea' cols='70' onClick=\"SelectAll('txtarea');\"  rows='5' name='code'>".$code."</textarea>";


You have to escape the quotes using backslash, so put in onClick=\"SelectAll('txtarea')\"

Same is recommended for the other attributes, e.g. cols=\"70\"


Why don't you make it easier on yourself? If you need single and double quotes within your string, you can use heredoc syntax, such as:

echo <<<EOF
<textarea id="textarea" cols="70" onClick="SelectAll('txtarea');" rows="5" name="code">$code</textarea>
EOF;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜