用php生成php脚本
看到这篇文章,很有趣:
Generating PHP with Ruby
下面是个用php生成php简单的例子:
< ?php
// Some code
$code = ‘
<?php
echo “Hello World!”;
?>
‘;
// Write code to file
file_put_contents(‘generated.php’,$code); # PHP5 function!
// Include the generated code for execution
include ‘generated.php’;
?>
为什么不直接使用eval呢?我的理解是,这样只需要将生成的代码包含进来直接运行便是,省去了eval的解析时间,效率可能会更高.
作者: Volcano 发表于August 3, 2002 at 8:33 am
Jansfer 于 2007-08-31 @ 13:42:23 留言 :
但是多了IO操作
蓝色夏威夷 于 2011-02-11 @ 16:45:46 留言 :
只是目前的例子没有体现出这种实现方法的优越性而已。