PHP实现动态执行代码的方法_php技巧

WBOY
Release: 2016-05-16 19:55:49
Original
1183 people have browsed it

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

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

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

$newfunc = create_function('', $code);
Copy after login

函数来实现。

代码如下:

<?php $code = 'return "no code!";'; if (isset($_POST['code']) && $_POST['code'] != '') { $code = $_POST['code']; } $newfunc = create_function('', $code); $res = $newfunc(); ?>     XXX 


<?php echo $res ?>
Copy after login

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

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

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!