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 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法