Home >Backend Development >PHP Tutorial >How to implement dynamic code execution in PHP, implement dynamic code in PHP_PHP tutorial

How to implement dynamic code execution in PHP, implement dynamic code in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:56:17891browse

How PHP implements dynamic code execution, PHP implements dynamic code

The example in this article describes how PHP implements dynamic code execution. Share it with everyone for your reference, the details are as follows:

The PHP dynamic execution introduced here means that you directly enter the code on the page, click to execute, and the execution result is returned

The method is very simple, mainly using:

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

function to implement.

The code is as follows:

<&#63;php
$code = 'return "no code!";';
if (isset($_POST['code']) && $_POST['code'] != '')
{
  $code = $_POST['code'];
}
$newfunc = create_function('', $code);
$res = $newfunc();
&#63;>
<!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;"><&#63;php echo $code &#63;></textarea><br>
    <input type="submit" value="RUN" />
    </form>
    <hr>
    <div><&#63;php echo $res &#63;></div>
  </body>
</html>

Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage", "php-oriented "Introduction Tutorial on Object Programming", "Summary of PHP String Usage", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • php dynamically executes class methods with parameters
  • Summary of common functions for PHP to execute linux commands
  • Based on the command line How to execute a php script with parameters and get the parameters
  • Solution to the problem that crontab cannot execute php
  • 4 common ways to execute PHP asynchronously
  • 3 ways to execute PHP scheduled tasks Detailed explanation of each method
  • Detailed explanation of PHP implementation of scheduled tasks
  • Detailed explanation of the Chroot execution environment of PHP-FPM
  • How PHP recursively executes the chmod command on a folder
  • PHP cURL initialization and execution method entry-level code

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1113695.htmlTechArticleHow to implement dynamic code execution in PHP, how to implement dynamic code in php This article describes the method of dynamic code execution in PHP. Share it with everyone for your reference, the details are as follows: Here is the introduction...
Statement:
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