php v8js 执行外部js,php运行jsv8引擎

这两天在写markdown2html的功能,现有的ph扩展转换质量都很差,发现有一个to-markdown.js转换效果还算能满足需求,于是折腾了一个在php里运行v8引擎的小工具,写api来处理。

看到红薯有个翻译了一个demo:http://www.oschina.net/question/12_62525

Ubuntu 12.04下安装,部署到centos上的话,应该一样,但还没有测试

[shell]

sudo apt-get install php5-dev php-pear libv8-dev build-essential

sudo pecl install v8js

sudo pecl install channel://pecl.php.net/v8js-0.1.3

sudo echo extension=v8js.so >>/etc/php5/cli/php.ini

sudo echo extension=v8js.so >>/etc/php5/apache2/php.ini

php -m | grep v8

[/shell]

[php]

$markdown = 'to-markdown.js';

$markdown = file_get_contents($markdown);

$html = 'test.html';

$html = file_get_contents($html);

$html = str_replace("\r", '_+-r-+_', $html);

$html = str_replace("\n", '_+-n-+_', $html);

$html = addslashes($html);

$v8 = new V8Js();

$JS = <<< EOT

{$markdown}

var html= '{$html}';

toMarkdown(html);

EOT;

file_put_contents('my.js', $html);

$return = $v8->executeString($JS);

$return = str_replace('_+-r-+_', "\r", $return);

$return = str_replace("_+-n-+_", "\n", $return);

file_put_contents('result.txt', $return);

[/php]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值