View Full Version : echo double quotes for javascript
ggalan
07-22-2010, 06:25 PM
i have to echo out a line :
echo "<td valign='top' align='right' height='38'><a class='textBlockClick1' href='javascript:loadContent('#popoutBox', 'inst.html');'>click btn</a></td>";
but the single quote around javascript have to be double
href="javascript:loadContent('#popoutBox', 'inst.html');"
how can do this? or is there a workaround??
bluewalrus
07-22-2010, 06:41 PM
You can do it three ways
1. Use single quotes
2. Escape them with \
3. Just output it as html/javascript
1.
echo '<td valign="top" align="right" height="38"><a class="textBlockClick1" href="javascript:loadContent("#popoutBox", "inst.html");">click btn</a></td>';
2.
echo "<td valign=\"top\" align=\"right\" height=\"38\"><a class=\"textBlockClick1\" href=\"javascript:loadContent(\"#popoutBox\", \"inst.html\");\">click btn</a></td>";
3.
?>
<td valign="top" align="right" height="38"><a class="textBlockClick1" href="javascript:loadContent("#popoutBox", "inst.html");">click btn</a></td>
<?php
ggalan
07-22-2010, 06:56 PM
awesome, thank you.
btw what does escape do?
backslashing ( \ ) a special character (in this case, double-quotes) tells php to treat it as the literal character, and not parse it as php code.
bluewalrus
07-22-2010, 07:30 PM
Wasn't really sure of a good definition so here's a link. http://en.wikipedia.org/wiki/Escape_character
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.