Run js in php

Source: Internet
Author: User
I ran js in php and went to the zend website this day. I saw a monkeyspider tag,

Http://devzone.zend.com/article/4704-Using-JavaScript-in-PHP-with-PECL-and-SpiderMonkey

Hey, I used to write an extension php extension in c to link spiderMonkey with php. I tried it and ran it. I 'd like to share it with you.

First, download

Http://ftp.mozilla.org/pub/mozilla.org/js/ js-1.7

Http://pecl.php.net/package/spidermonkey spidermonkey php extension

  
Shell # tar-xzvf js-1.70.tar-gz
Shell # cd js/src
Shell # make-f Makefile. ref
Shell # mkdir-p/usr/local/include/js/
Shell # cp *. {h, tbl}/usr/local/include/js/

  shell# cd Linux_All_DBG.OBJ  shell# cp *.h /usr/local/include/js/   shell# cp js /usr/local/bin/   shell# cp libjs.so /usr/local/lib/  shell# ldconfig

Go to the spidermonkey and php extension directory,

shell# phpizeshell# ./configureshell# makeshell# make install

Errors may be reported during make. comment the lines that are reported with errors. use the attributes not found in php struct to open the extension in php. ini.
              

Code

Assign ('A', $ a); $ js-> assign ('B', $ B ); // define script code $ script = <END c = a + B; END; // evaluate script and display result echo "The sum of $ a and $ B is: ". $ js-> evaluateScript ($ script);?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.