mottwsc Posted October 23, 2009 Share Posted October 23, 2009 This statement will render in HTML: <b><a href="javascript:animate.show(['why', 'how1', 'how2'])"><img src="show.jpeg" border="0" /></a></b> However, if I want to use an echo statement (because I am controlling it as part of a PHP script), I run into a problem since there are already double quotes around the javascript call and single quotes around arguments within the call. If I'm going to use echo and wrap the whole thing in double quotes, I would normally use single quotes around the javascript call, but what about the single quotes already there for the arguments? Thank you. Link to comment https://forums.phpfreaks.com/topic/178748-solved-echo-with-multiple-levels-of-quotes/ Share on other sites More sharing options...
Bricktop Posted October 23, 2009 Share Posted October 23, 2009 Hi mottwsc, Escape the single quotes using a backslash \, i.e.: <b><a href="javascript:animate.show([\'why\', \'how1\', \'how2\'])"><img src="show.jpeg" border="0" /></a></b> Hope this helps. Link to comment https://forums.phpfreaks.com/topic/178748-solved-echo-with-multiple-levels-of-quotes/#findComment-942890 Share on other sites More sharing options...
mottwsc Posted October 23, 2009 Author Share Posted October 23, 2009 By that, I assume that translates when quoted for the echo statement into the following, right? echo '<b><a href="javascript:animate.show([\'why\', \'how1\', \'how2\'])"><img src="show.jpeg" border="0" /></a></b>'; Link to comment https://forums.phpfreaks.com/topic/178748-solved-echo-with-multiple-levels-of-quotes/#findComment-942904 Share on other sites More sharing options...
salathe Posted October 23, 2009 Share Posted October 23, 2009 Perhaps the HEREDOC syntax might be of use? echo <<<HEREDOC <b><a href="javascript:animate.show(['why', 'how1', 'how2'])"><img src="show.jpeg" border="0" /></a></b> HEREDOC; Link to comment https://forums.phpfreaks.com/topic/178748-solved-echo-with-multiple-levels-of-quotes/#findComment-942905 Share on other sites More sharing options...
Bricktop Posted October 23, 2009 Share Posted October 23, 2009 By that, I assume that translates when quoted for the echo statement into the following, right? echo '<b><a href="javascript:animate.show([\'why\', \'how1\', \'how2\'])"><img src="show.jpeg" border="0" /></a></b>'; Hi mottwsc, No, it will translate as: echo '<b><a href="javascript:animate.show(['why', 'how1', 'how2'])"><img src="show.jpeg" border="0" /></a></b>'; The backslashes will not be echo'd Hope this helps. Link to comment https://forums.phpfreaks.com/topic/178748-solved-echo-with-multiple-levels-of-quotes/#findComment-942909 Share on other sites More sharing options...
mottwsc Posted October 23, 2009 Author Share Posted October 23, 2009 thanks to all. Link to comment https://forums.phpfreaks.com/topic/178748-solved-echo-with-multiple-levels-of-quotes/#findComment-942917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.