PHP code example of pwt777 / phpexecjs

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;
      };

    $square = $phpexecjs->call("CoffeeScript.compile", ["square = (x) -> x * x", ['bare' => true]]);
    $phpexecjs->createContext($square);
    print_r($phpexecjs->evalJs('square(3)'));

    $myRuntime = new ExternalRuntime('My runtime name', 'my_command');
    $phpExecJs = new PhpExecJs($myRuntime);