I believe it is possible to execute a java script function within PHP, but will it then remain server side as opposed to client side? Can I, within PHP, call a .js function, passing it some args, and have it return to the PHP that called it?
A script I want to use returns XML, and I want to get the user inputs using PHP, pass them to the .js function residing on the server, then take the returned xml and parse it back in the PHP part.
I ask because I see people commenting that because .js is client side and PHP is server side, they don't get along. I was hoping that by executing the .js function in the PHP, I could spoof the .js call as coming from the local machine (the server).
Thanks for any information!
Yes possible. You can write PHP code in html and can link js also.
The way to pass a JavaScript variable to PHP is through a request. This type of URL is only visible if we use the GET action, the POST action hides the information in the URL. Server Side(PHP): On the server side PHP page, we request for the data submitted by the form and display the result. $result = $_GET [ 'data' ];
You cannot call JavaScript from within PHP itself. PHP is not a JavaScript engine.
However, there is a PECL Extension for interfacing with V8:
And you can interface with a (serverside) JavaScript engine. Have a look at node.js and
You could if you found a server-side Javascript interpreter that you could call out to. I haven't used PHPJS (http://phpjs.berlios.de/) but it might work.
It sounds like your better bet is to replace the js code, because what you're doing just sounds like a bad idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With