PHP file_get_contents after php has evaluated

前端 未结 1 1970
生来不讨喜
生来不讨喜 2021-01-06 07:09

I know how to use file_get_contents and fopen etc, but when I do it to one of my own file, I get the literal string, meaning, the code is not preprocessed! How can i import

1条回答
  •  时光取名叫无心
    2021-01-06 07:35

    See examples #5 and #6 on the manual. Taken straight from there:

    $string = get_include_contents('somefile.php');
    
    function get_include_contents($filename) {
        if (is_file($filename)) {
            ob_start();
            include $filename;
            $contents = ob_get_contents();
            ob_end_clean();
            return $contents;
        }
        return false;
    }
    

    0 讨论(0)
提交回复
热议问题