How to call a JavaScript function from PHP?

后端 未结 10 2359
误落风尘
误落风尘 2020-11-21 23:03

How to call a JavaScript function from PHP?

The followi

10条回答
  •  一向
    一向 (楼主)
    2020-11-21 23:41

    If you want to echo it out for later execution it's ok

    If you want to execute the JS and use the results in PHP use V8JS

    V8Js::registerExtension('say_hi', 'print("hey from extension! "); var said_hi=true;', array(), true);
    $v8 = new V8Js();
    $v8->executeString('print("hello from regular code!")', 'test.php');
    $v8->executeString('if (said_hi) { print(" extension already said hi"); }');
    

    You can refer here for further reference: What are Extensions in php v8js?

    If you want to execute HTML&JS and use the output in PHP http://htmlunit.sourceforge.net/ is your solution

提交回复
热议问题