php,缓存数据流(标准输出)
缓存php数据输出
#用ob_start函数开始缓存php输出
ob_start();
#这里执行php代码等等,有输出,如echo等等.
#...
#...
#完毕,用函数ob_get_contents获取截获的缓存数据
$contents = ob_get_contents();
#用函数ob_end_clean结束缓存php输出.
ob_end_clean();
然后再处理$content,如压缩,保存到文件,数据库等等.
给出一个一般性的函数,用于取得另一个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;
}
#需要注意的是,$filename是被include到函数get_include_contents中,所以得自己维护全局变量.比如, 如果$filename中用到了$_GET,则无效,需要在$filename中用 global $_GET;来声明.切记
#用ob_start函数开始缓存php输出
ob_start();
#这里执行php代码等等,有输出,如echo等等.
#...
#...
#完毕,用函数ob_get_contents获取截获的缓存数据
$contents = ob_get_contents();
#用函数ob_end_clean结束缓存php输出.
ob_end_clean();
然后再处理$content,如压缩,保存到文件,数据库等等.
给出一个一般性的函数,用于取得另一个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;
}
#需要注意的是,$filename是被include到函数get_include_contents中,所以得自己维护全局变量.比如, 如果$filename中用到了$_GET,则无效,需要在$filename中用 global $_GET;来声明.切记
浙公网安备 33010602011771号