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++) //通過循環進行操作
- {//開源代碼Vevb.com
- 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"; //輸出內容
新聞熱點
疑難解答