php缓冲输出实例分析

2025-05-29 0 48

本文实例讲述了php缓冲输出用法。分享给大家供大家参考。具体分析如下:

ob_start([string output_callback])- 打开输出缓冲

所有的输出信息不在直接发送到浏览器,而是保存在输出缓冲区里面,可选得回调函数用于处理输出结果信息.

ob_end_flush – 结束(发送)输出缓冲区的内容,关闭输出缓冲

实例代码如下:

复制代码 代码如下:

ob_start(); //打开缓冲
echo "hello world"; //输出内容
$out=ob_get_clean(); //获得缓冲区内容并且结束缓冲
$out=strtolower($out); //将字符转换为小写
var_dump($out); //输出结果
//

if(!function_exists('ob_clean')) //判断函数是否被定义
{
function ob_clean() //定义函数
{
if(@ob_end_clean())
{
return ob_start();
}
trigger_error("ob_clean() failed to delete buffer.no buffer to delete.",e_user_notice);
return false;
}
}
//

header('content-type: multipart/x-mixed-replace;boundary=endofsection'); //发送标头
print "n–endofsectionn"; //输出内容
$pmt=array("-","","|","/"); //定义数组
for($i=0;$i<10;$i++) //通过循环进行操作
{
sleep(1); //暂停执行
print "content-type: text/plainnn"; //输出内容
print "part $it".$pmt[$i % 4]; //输出内容
print "–endofsectionn"; //输出内容
ob_flush(); //发送缓冲区数据
flush(); //刷新输出缓冲
}
print "content-type: text/plainnn"; //输出内容
print "the endn"; //输出内容
print "–endofsection–n"; //输出内容

希望本文所述对大家的php程序设计有所帮助。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 php缓冲输出实例分析 https://www.kuaiidc.com/103640.html

相关文章

发表评论
暂无评论