Home > Backend Development > PHP Tutorial > PHP method to dynamically execute code_php tips

PHP method to dynamically execute code_php tips

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

The example in this article describes the method of dynamically executing code in PHP. Share it with everyone for your reference, the details are as follows:

The PHP dynamic execution introduced here means entering the code directly on the page, clicking to execute, and returning the execution results

The method is very simple, mainly using:

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

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>

Copy after login

Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP operating office document skills (including word, excel, access, ppt)", "php date Time usage summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation Introductory tutorial " and " Summary of common PHP database operation skills "

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

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template