PHP文件\u在PHP评估后获取\u内容

PHP文件\u在PHP评估后获取\u内容,php,import,fopen,require,Php,Import,Fopen,Require,我知道如何使用file\u get\u contents和fopen等,但是当我对我自己的一个文件这样做时,我得到了文本字符串,这意味着代码没有经过预处理!如何在不使用require等的情况下从文件导入文本,因为我想将值存储到字符串中请参见上的示例5和示例6。从那里直接拍摄: $string = get_include_contents('somefile.php'); function get_include_contents($filename) { if (is_file($fi

我知道如何使用file\u get\u contents和fopen等,但是当我对我自己的一个文件这样做时,我得到了文本字符串,这意味着代码没有经过预处理!如何在不使用require等的情况下从文件导入文本,因为我想将值存储到字符串中

请参见上的示例5和示例6。从那里直接拍摄:

$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;
}

文件获取内容应该有效。发布有问题的代码。所以你在一个文件中有代码,你想执行它并对结果做些什么?我想他是说他想得到脚本输出的文本。你为什么不能使用require/include?别担心,我现在明白你的意思了。用chigley的解决方案伙计我爱你这工作很神奇