gpt4 book ai didi

php - 有没有办法从 PHP 代码加载的文件中解析 PHP?

转载 作者:太空宇宙 更新时间:2023-11-04 15:33:40 26 4
gpt4 key购买 nike

我正在使用

从外部文本文件加载 HTML/PHP 代码
$f = fopen($filename, "r");
while ($line = fgets($f, 4096))
{
print $line;
}

有没有办法让服务器解析这个文件中的 PHP 代码?我目前只使用一个简单的 <?php echo("test"); ?>在外部文件(保存在 $filename 中)来测试它是否有效。我尝试使用 ob_start()ob_end_flush()在主文件中,但无济于事。我对其他解决方案持开放态度,但如果可能的话,我想保持文件的分离并仅使用 PHP 来简化网站的 future 升级。

最佳答案

看起来您正在寻找这个:http://php.net/manual/en/function.eval.php

但请牢记警告:

The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.

如果有的话,尝试寻找不同的解决方案?

关于php - 有没有办法从 PHP 代码加载的文件中解析 PHP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11084764/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com