Question:
How can I insert Javascript code into a PHP function?
anonymous
1970-01-01 00:00:00 UTC
How can I insert Javascript code into a PHP function?
Six answers:
anonymous
2016-05-18 07:47:22 UTC
... I'm not at all sure what you want to do. Are you trying to save a code snippet to your database (and I really can't fathom why you'd want to do that...), or are you trying to figure out how to run that code and have it execute your query? Also, you don't seem to have any kind of database connection logic... you won't be inserting anything without it. You're going to have to provide more info on what you're trying to accomplish, because I'm lost.
galt_57
2012-07-26 07:32:25 UTC
Why? What you probably want is Ajax, which is a technique that allows Javascript and PHP to talk to each other.
anonymous
2012-07-26 13:45:48 UTC

function myplugin()

{

$js='';

return $js;

}



echo myplugin();

?>
anonymous
2012-07-26 07:40:09 UTC
simply, dear :-)






print("");



?>
anonymous
2012-07-26 06:55:20 UTC
Get A HUGE A$$ HAMMER AND SLAM IT INTO THE PP FUNCTION
anonymous
2012-07-26 07:00:18 UTC
PHP is typically (though not necessarily) used in such a way that all output is sent to the browser. If you want to send the JavaScript to the browser through PHP then you can do it using regular echo:



echo '



';



Note that, since inside the JavaScript snippet, quotes were used, you should demarcate the echo'ed text using apostrophes.



Alternatively, you can use docstrings:



echo <<


BARFY



However, if you want to execute JavaScript from within PHP, well, then you're out of luck. I can't think of a reason WHY you'd want that, nor can I think of a way HOW to do it. The latter being a consequence of the former.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...