php緩沖輸出實(shí)例分析
本文實(shí)例講述了php緩沖輸出用法。分享給大家供大家參考。具體分析如下:
ob_start([string output_callback])- 打開輸出緩沖區(qū)
所有的輸出信息不在直接發(fā)送到瀏覽器,而是保存在輸出緩沖區(qū)里面,可選得回調(diào)函數(shù)用于處理輸出結(jié)果信息.
ob_end_flush - 結(jié)束(發(fā)送)輸出緩沖區(qū)的內(nèi)容,關(guān)閉輸出緩沖區(qū)
實(shí)例代碼如下:
echo "hello world"; //輸出內(nèi)容
$out=ob_get_clean(); //獲得緩沖區(qū)內(nèi)容并且結(jié)束緩沖區(qū)
$out=strtolower($out); //將字符轉(zhuǎn)換為小寫
var_dump($out); //輸出結(jié)果
//
if(!function_exists('ob_clean')) //判斷函數(shù)是否被定義
{
function ob_clean() //定義函數(shù)
{
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'); //發(fā)送標(biāo)頭
print "n--endofsectionn"; //輸出內(nèi)容
$pmt=array("-","","|","/"); //定義數(shù)組
for($i=0;$i<10;$i++) //通過循環(huán)進(jìn)行操作
{
sleep(1); //暫停執(zhí)行
print "content-type: text/plainnn"; //輸出內(nèi)容
print "part $it".$pmt[$i % 4]; //輸出內(nèi)容
print "--endofsectionn"; //輸出內(nèi)容
ob_flush(); //發(fā)送緩沖區(qū)數(shù)據(jù)
flush(); //刷新輸出緩沖
}
print "content-type: text/plainnn"; //輸出內(nèi)容
print "the endn"; //輸出內(nèi)容
print "--endofsection--n"; //輸出內(nèi)容
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
不用mod_rewrite直接用php實(shí)現(xiàn)偽靜態(tài)化頁面代碼
不用mod_rewrite直接用php代碼實(shí)現(xiàn)偽靜態(tài)效果,大家看后就會(huì)發(fā)現(xiàn)php真的很方便2008-10-10PHP對(duì)象、模式與實(shí)踐之高級(jí)特性分析
這篇文章主要介紹了PHP對(duì)象、模式與實(shí)踐之高級(jí)特性,結(jié)合實(shí)例形式分析了php面向?qū)ο蟪绦蛟O(shè)計(jì)中的靜態(tài)屬性和方法、抽象類、接口、攔截器、克隆對(duì)象等概念與簡單實(shí)現(xiàn)方法,需要的朋友可以參考下2016-12-12