如何回显将执行的php代码?
我正在制作一个网站,想要执行以下操作,但我不知道如何操作: 用 PHP 代码回显 HTML 代码,以便执行 PHP 代码。我读取了该文件并回显它,但 PHP 代码只是一串文本并且不执行。
例如:
[一个网站文件 dude.php]
<html>
<?php
echo "dude";
?>
</html>
[另一个网站文件,尝试回显 dude.php 文件,并执行 PHP 代码]
<?php
$pathToFile = 'dude.php';
$myFile = fopen($pathToFile, 'r');
$theData = fread($myFile, filesize($pathToFile));
echo $theData;
fclose($myFile);
?>
但我得到的只是回显 dude.php,但未执行 PHP 代码。
我不明白为什么,也许有一些与“echo”命令有关的东西......
我希望这足够清楚,让人们能够理解。我真的不知道还有什么其他方法可以解释它。
I am making a website and would want to do the following, but I have no idea how:
echo out HTML code with PHP code, so the PHP code executes. I read the file and echo it, but the PHP code is just a string of text and does not execute.
For example:
[a website file dude.php]
<html>
<?php
echo "dude";
?>
</html>
[another website file, that tries to echo out dude.php file, with the PHP code executed]
<?php
$pathToFile = 'dude.php';
$myFile = fopen($pathToFile, 'r');
$theData = fread($myFile, filesize($pathToFile));
echo $theData;
fclose($myFile);
?>
But all I get, is dude.php echoed out with the PHP code not executed.
I do not understand why, maybe there is something with the "echo" command...
I hope that this was clear enough for people to understand. I really don't know any other way to explain it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在寻找
include
语句。You're looking for the
include
statement.使用 eval($somePhpCode) 评估字符串代码。
-文档-
但也许您也想使用 include。
Evaluate string code wiht eval($somePhpCode).
-Documentation-
But maybe you want to use include as well.