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" style="width:100%; height:300px;"><?php echo $code ?></textarea><br> <input type="submit" value="RUN" /> </form> <hr> <div><?php echo $res ?></div> </body> </html>
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
- php 动态执行带有参数的类方法
- PHP执行linux命令常用函数汇总
- 基于命令行执行带参数的php脚本并取得参数的方法
- crontab无法执行php的解决方法
- 4种PHP异步执行的常用方式
- PHP定时执行任务的3种方法详解
- 详解PHP实现执行定时任务
- PHP-FPM之Chroot执行环境详解
- PHP对文件夹递归执行chmod命令的方法
- PHP cURL初始化和执行方法入门级代码

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment