Store Javascript function in PHP -


i can't life of me figure out how store javascript function in php variable. want store function standard string in php variable, , get's printed out on page. know have escape javascript have work php, reason i'm stuck on because particular javascript , html combination seems make use of both " , ' can't figure out how escape it. maybe guys me out?

here's code want store in php variable:

<a href='javascript:popupcontact_openform("popupcontact_boxcontainer","popupcontact_boxcontainerbody","popupcontact_boxcontainerfooter");'><img src='/popup-contact-form.jpg' /></a> <div style="display: none;" id="popupcontact_boxcontainer">     <div id="popupcontact_boxcontainerheader">         <div id="popupcontact_boxtitle">contact us</div>         <div id="popupcontact_boxclose"><a href="javascript:popupcontact_hideform('popupcontact_boxcontainer','popupcontact_boxcontainerfooter');">close</a></div>     </div>     <div id="popupcontact_boxcontainerbody">         <form action="#" name="popupcontact_form" id="popupcontact_form">         <div id="popupcontact_boxalert"> <span id="popupcontact_alertmessage"></span> </div>         <div id="popupcontact_boxlabel_page"> name </div>         <div id="popupcontact_boxlabel_page"><input name="popupcontact_name" class="popupcontact_textbox" type="text" id="popupcontact_name" maxlength="120"></div>         <div id="popupcontact_boxlabel_page"> email </div>         <div id="popupcontact_boxlabel_page"><input name="popupcontact_email" class="popupcontact_textbox" type="text" id="popupcontact_email" maxlength="120"></div>         <div id="popupcontact_boxlabel_page"> enter message </div>         <div id="popupcontact_boxlabel_page"><textarea name="popupcontact_message" class="popupcontact_textarea" rows="3" id="popupcontact_message"></textarea></div>         <div id="popupcontact_boxlabel_page"><input type="button" name="button" class="popupcontact_button" value="submit" onclick="javascript:popupcontact_submit(this.parentnode,'/popup-contact-form/');"></div>     </form>     </div> </div>         <div style="display: none;" id="popupcontact_boxcontainerfooter"></div> 

hopefully can see mean, want store in $button variable

thanks!

you put whole thing in single quotes , escape every single quote within \', nicer approach use php's nowdoc syntax:

$str = <<<'str_html'   // html goes here str_html; 

if you're php version earlier 5.3 can't use nowdoc, should use heredoc instead. difference difference between double quotes (heredoc) , single quotes (nowdoc).

see php manual page on strings more information.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -