PHP 8.6.0 Beta 1 is available for testing

Примеры

Основы использования

Пример #1 Запуск Javascript

<?php
$v8 = new V8Js();
/* basic.js */
$JS = <<< EOT
len = print('Hello' + ' ' + 'World!' + "\\n");
len;
EOT;
try {
 var_dump($v8->executeString($JS, 'basic.js'));
} catch (V8JsException $e) {
 var_dump($e);
}
?>

Результат выполнения приведённого примера:

Hello World!
int(13)

Нашли ошибку?

ИнструкцияИсправлениеСообщение об ошибке
+Добавить

Примечания пользователей 1 note

up
1
nabikaz at gmail dot com
3 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 result
var_dump($result);
?>

Output:
string(12) "Hello World!"
+Добавить

AltStyle によって変換されたページ (->オリジナル) /