php緩衝輸出執行個體分析,php緩衝執行個體分析_PHP教程

來源:互聯網
上載者:User

php緩衝輸出執行個體分析,php緩衝執行個體分析


本文執行個體講述了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程式設計有所協助。

http://www.bkjia.com/PHPjc/937724.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/937724.htmlTechArticlephp緩衝輸出執行個體分析,php緩衝執行個體分析 本文執行個體講述了php緩衝輸出用法。分享給大家供大家參考。具體分析如下: ob_start([string output_ca...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.