在PHP中执行javascript [英] Executing javascript within PHP
问题描述
我相信可以在PHP中执行java脚本函数,但它是否会保留服务器端而不是客户端?我可以在PHP中调用.js函数,传递一些args,让它返回到调用它的PHP吗?
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?
我想要使用的脚本返回XML,我希望使用PHP获取用户输入,将它们传递给驻留在服务器上的.js函数 ,然后获取返回的xml并将其解析回PHP部分。
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.
我问,因为我看到人们评论,因为.js是客户端而PHP是服务器端,他们不相处。我希望通过在PHP中执行.js函数,我可以将.js调用欺骗来自本地机器(服务器)。
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).
感谢任何人信息!
推荐答案
您无法从PHP本身调用JavaScript。 PHP不是JavaScript引擎。
You cannot call JavaScript from within PHP itself. PHP is not a JavaScript engine.
然而,有一个PECL扩展用于与V8接口:
However, there is a PECL Extension for interfacing with V8:
- < a href =http://php.net/manual/en/book.v8js.php =nofollow noreferrer> http://php.net/manual/en/book.v8js.php
- http://we-love-php.blogspot.de/2012/07/using-v8-javascript-engine-as-php.html
- http://php.net/manual/en/book.v8js.php
- http://we-love-php.blogspot.de/2012/07/using-v8-javascript-engine-as-php.html
您可以与(服务器端)JavaScript引擎连接。请查看 node.js 和
And you can interface with a (serverside) JavaScript engine. Have a look at node.js and
- Recommendation for integrating nodejs with php application
这篇关于在PHP中执行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!