Beispiele

Einfache Anwendungsbeispiele

Beispiel #1 Einfache Ausführung von JavaScript

<?php

$v8
= new V8Js();

/* basic.js */
$JS = <<< EOT
len = print('Hallo' + ' ' + 'Welt!' + "\\n");
len;
EOT;

try {
var_dump($v8->executeString($JS, 'basic.js'));
} catch (
V8JsException $e) {
var_dump($e);
}

?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Hallo Welt!
int(12)
add a note

User Contributed Notes 1 note

up
0
nabikaz at gmail dot com
2 years ago
If you want the output of the JS code not to be printed in the output and have it in PHP:<?php// Create a new V8Js object$v8 = new V8Js();// Define a JavaScript function$JS = <<<EOT    (function() {        return 'Hello World!';    })();EOT;// Execute the JavaScript function using V8js$result = $v8->executeString($JS);// Output the resultvar_dump($result);?>Output:string(12) "Hello World!"
To Top