1. Go to this page and download the library: Download pwt777/phpexecjs library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pwt777 / phpexecjs example snippets
use Nacmartin\PhpExecJs\PhpExecJs;
$phpexecjs = new PhpExecJs();
print_r($phpexecjs->evalJs("'red yellow blue'.split(' ')"));
$phpexecjs->createContextFromFile("http://coffeescript.org/extras/coffee-script.js");
print_r($phpexecjs->call("CoffeeScript.compile", ["square = (x) -> x * x", ['bare' => true]]));
That will print:
var square;
square = function(x) {
return x * x;
};