PHP在获取文件内容之前评估代码 [英] php evaluate code before getting file content

查看:89
本文介绍了PHP在获取文件内容之前评估代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件B590.php,其中包含很多html代码和一些php代码(例如,登录的用户名,用户详细信息).

I have a file B590.php which is having a lot of html code and some php code (eg logged in username, details of user).

我尝试使用$html = file_get_content("B590.php");

但是$html然后将B90.php的内容作为纯文本(带有php代码).

But then $html will have the content of B90.php as plain text(with php code).

是否有任何方法可以在评估文件后获取文件的内容? 似乎有许多相关问题,例如此问题

Is there any method where I can get the content of the file after it has been evaluated? There seems to be many related questions like this one and this one but none seems to have any definite answer.

推荐答案

    function get_include_contents($filename){
      if(is_file($filename)){
        ob_start();
        include $filename;
        $contents = ob_get_contents();
        ob_end_clean();
        return $contents;
      }
      return false;
    }

    $html = get_include_contents("/playbooks/html_pdf/B580.php");

此答案最初发布在Stackoverflow

This answer was originally posted on Stackoverflow

这篇关于PHP在获取文件内容之前评估代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆