PHP file_get_contents with php intact?

后端 未结 6 1257
后悔当初
后悔当初 2021-02-15 16:30

As opposed to using an include, which executes the included php in the file...is it possible to save the contents of a php file to a variable - but with the php still intact and

6条回答
  •  自闭症患者
    2021-02-15 17:14

    How about this...

    function getTemplate($file) {
    
        ob_start(); // start output buffer
    
        include $file;
        $template = ob_get_contents(); // get contents of buffer
        ob_end_clean();
        return $template;
    
    }
    

    Basically, this will get whatever $file is, and parse it with PHP, then return the output into a variable.

提交回复
热议问题