要求/包含到变量中 [英] require/include into variable
本文介绍了要求/包含到变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要求/包含一个文件,并将其内容检索到一个变量中.
I want to require/include a file and retrieve its contents into a variable.
test.php
<?php
echo "seconds passed since 01-01-1970 00:00 GMT is ".time();
?>
index.php
<?php
$test=require("test.php");
echo "the content of test.php is:<hr>".$test;
?>
类似于file_get_contents()
,但仍应执行PHP代码.
这可能吗?
Like file_get_contents()
but than it should still execute the PHP code.
Is this possible?
推荐答案
我也遇到过这个问题,尝试尝试类似
I've also had this issue once, try something like
<?php
function requireToVar($file){
ob_start();
require($file);
return ob_get_clean();
}
$test=requireToVar($test);
?>
这篇关于要求/包含到变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文