手机
当前位置:查字典教程网 >编程开发 >php教程 >PHP实现动态执行代码的方法
PHP实现动态执行代码的方法
摘要:本文实例讲述了PHP实现动态执行代码的方法。分享给大家供大家参考,具体如下:这里介绍的PHP动态执行,即在页面上直接输入代码,点击执行,返回...

本文实例讲述了PHP实现动态执行代码的方法。分享给大家供大家参考,具体如下:

这里介绍的PHP动态执行,即在页面上直接输入代码,点击执行,返回执行结果

方法很简单,主要使用了:

$newfunc = create_function('', $code);

函数来实现。

代码如下:

<?php $code = 'return "no code!";'; if (isset($_POST['code']) && $_POST['code'] != '') { $code = $_POST['code']; } $newfunc = create_function('', $code); $res = $newfunc(); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>XXX</title> </head> <body> <form action="run.php" method="POST"> <textarea name="code"><?php echo $code ?></textarea><br> <input type="submit" value="RUN" /> </form> <hr> <div><?php echo $res ?></div> </body> </html>

希望本文所述对大家PHP程序设计有所帮助。

【PHP实现动态执行代码的方法】相关文章:

PHP递归调用数组值并用其执行指定函数的方法

PHP实现根据银行卡号判断银行

PHP+shell实现多线程的方法

Yii实现自动加载类地图的方法

php格式化电话号码的方法

PHP实现分页的一个示例

PHP基于MySQL数据库实现对象持久层的方法

用PHP实现登陆验证码(类似条行码状)

php使用array_search函数实现数组查找的方法

PHP4中实现动态代理

精品推荐
分类导航