edt*_*edt 45 php output-buffering echo output
在PHP中,有没有办法清除/删除所有以前回显或打印的项目?
例如:
<?php
echo 'a';
print 'b';
// some statement that removes all printed/echoed items
echo 'c';
// the final output should be equal to 'c', not 'abc'
?>
Run Code Online (Sandbox Code Playgroud)
我的脚本使用include函数.包含的文件不应该回应任何东西.为了防止有人(ex = hacker)尝试,我需要一种方法来删除.
Mat*_*ley 96
<?php
ob_start();
echo 'a';
print 'b';
// some statement that removes all printed/echoed items
ob_end_clean();
echo 'c';
// the final output is equal to 'c', not 'abc'
?>
Run Code Online (Sandbox Code Playgroud)
输出缓冲函数在hackery中也很有用,可以强制只打印返回字符串的函数,即.
<?php
ob_start();
var_dump($myVar);
$data = ob_get_clean();
// do whatever with $data
?>
Run Code Online (Sandbox Code Playgroud)