doukang7486 2015-06-17 22:37
浏览 84
已采纳

如何从外部文件显示/执行PHP?

I have 2 files.

test.zt with the content of a lot of PHP and HTML come.

index.php where I'm including test.zt to display it's contents.


What I want to do now is to load test.zt contents into a variable (or something to be able to temporarily edit it). When it's done I want to use str_replace() function to change some text in the test.zt file temporarily. I do not want to overwrite the original test.zt source file.

After that I would like to display the changed file's content to the visitor.

Note: the code is containing PHP code and the page needs to execute that PHP code as well.

I have already tried to open the file with file_get_contents() and then echo out the contents, but it did not execute the PHP side of the content.

Is there any possibility to make this happen?

  • 写回答

4条回答 默认 最新

  • dongmao7195 2015-06-18 08:27
    关注

    Basically, you are asking for what eval does. But before you use that, please do some research on what downsides that has.

    Instead of using str_replace to “change some text”, you should probably rather just include a normal PHP file, and have that use variables from the main script to output parts of content that need to be dynamic.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大