我知道如何使用file_get_contents和fopen等,但当我对自己的文件执行此操作时,我得到了文字字符串,这意味着代码未经过预处理!如何在不使用require等的情况下从文件导入文本,因为我想将值存储到字符串
中答案 0 :(得分:10)
参见the manual上的示例#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;
}