Is it possible to run some javascript expression? egecho eval("Math.sqrt('25')");
echo eval("Math.sqrt('25')");
In normal situations:
So no, it's not entirely possible for PHP to execute some Javascript code on the server.
But at least there is a PHP extension that embeds (or wraps around) the Javascript engine and, as a result, allows you to run Javascript on the server, starting with PHP.
The extension I'm thinking of is spidermonkey : installing and enabling it on your server will allow you to execute Javascript code on a server with PHP.
, PHP, , , , .
, , , ... , , , :
echo "<script language='javascript'> Math.sqrt('25') </script>"
J4P5
, , , GPL.
php div javascript
html/php part
<div id="mybox" style="visibility:hidden;"> echo sqrt(25); </div>
javascript
var myfield = document.getElementById("mybox"); myfield.visibility = 'visible';
- ...
alert(myfield);
PHP - , , Javascript - , , JavaScript Javascript ( , HTML), .
echo sqrt(25);
:
http://php.net/manual/en/function.sqrt.php
JavaScript PHP
php v8js: https://github.com/phpv8/v8js
$v8 = new V8Js; $v8->executeString("Math.sqrt('25')"); // 5
https://github.com/chenos/execjs
use Chenos\ExecJs\Context; $cxt = new Context; $cxt->eval("Math.sqrt('25')"); // 5