js+运行+php+文件,php中运行JS

引用

A simple ./configure; make; make install should do the trick. Make sure to add an extension=js.so line to your php.ini/php.d. Note: you need to install libjs first. If you're using a Redhat-esque system, you can use the SRPM provided above, else, use the TBZ. Then, just use js_eval to evaluate your JavaScript. js_eval returns the value returned by the JavaScript interpreter to PHP. For example: js_eval("var a = 123;"); js_eval("var b = 456;"); $c = js_eval("[a, b];"); echo "a is ".$c[0]."\n"; echo "b is ".$c[1]."\n"; js_eval("var sum = function(x, y) { return x + y; }"); $d = js_eval("sum(a, b);"); echo "The sum of a and b is ".$d."\n"; Would produce: a is 123 b is 456 The sum of a and b is 579 js_eval takes an optional boolean argument, assoc, which returns objects as associative arrays instead of PHP objects. The php-js execution environment provides two built-in JavaScript system functions: * print * gc print outputs its argument to the php output stream. gc forces garbage collection within the JavaScript environment.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值