如何清除PHP中以前回显的项目 [英] How to clear previously echoed items in PHP

查看:67
本文介绍了如何清除PHP中以前回显的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在php中,有什么方法可以清除/删除所有先前回显或打印的项目?

In php, is there any way to clear/remove all previously echoed or printed items?

例如:

<?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'

?>

我的脚本使用了include函数.所包含的文件不应回显任何内容.万一有人(例如黑客)尝试,我需要一种删除方法.

My script uses the include function. The included files are not supposed to echo anything. Just in case someone (ex = hacker) tries, I need a way to remove.

推荐答案

<?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'

?>

输出缓冲功能

输出缓冲功能在黑客中也非常有用,可以强制仅打印返回字符串的功能.

The output buffering functions are also useful in hackery to coerce functions that only print to return strings, ie.

<?php
ob_start();
var_dump($myVar);
$data = ob_get_clean();
// do whatever with $data
?>

这篇关于如何清除PHP中以前回显的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆