PHP經驗——輸出緩衝區處理函數:ob_start、ob_get_contents、ob_end_clean、ob_end_flush

來源:互聯網
上載者:User

輸出緩衝區處理函數的作用有點類似C的堆棧,臨時放入一個儲存空間中,對內容進行處理。

輸出緩衝區函數有:

  • ob_start() - 開啟輸出控制緩衝
  • ob_get_length() - 返回輸出緩衝區的長度
  • ob_get_level() - 返回輸出緩衝區的嵌套層級
  • ob_get_status() - 返回輸出緩衝區的狀態(數組形式返回,預設返回最頂層,參數為true時返回所有)
  • ob_get_contents() - 返回輸出緩衝區的內容
  • ob_get_clean() - 以字串格式返回當前輸出緩衝區並關閉輸出緩衝
  • ob_end_clean() - 清空(擦除)緩衝區並關閉輸出緩衝
  • ob_get_flush() - 以字串返回輸出緩衝區內容並關閉緩衝
  • ob_end_flush() - 沖刷出(送出)輸出緩衝區內容緩衝

執行個體如下:

<?php   define('APP_ROOT', dirname(__FILE__)); $file = '/templates/html/error_config.html'; ob_start();  include(APP_ROOT.$file); ob_end_flush();   //$contents = ob_get_contents();  這樣可以將輸出儲存,可以作進一步處理  //ob_end_clean();   //echo $contents; ?>
<?php echo"<?xml version=\"1.0\" encoding=\"utf-8\">"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD  XHTML 1.0  Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />     <meta http-equiv="Content-Script-Type" content="text/javascript" />     <meta http-equiv="Content-Style-Type" content="text/css" />     <title>Error</title> </head> <body onload="doRedirect()"> <h1>Error</h1> <div style="position:absolute;top:150px;text-align:center;width:95%;">     <p style="margin:12pt;"><strong>config.php</strong> does not exist or is not readable by the webserver in the directory.</p>     <p style="margin:12pt;"><?php echo CommonFunctions::$PSI_VERSION_STRING ?></p> </div> </body> </html> 

輸出結果如下:

config.php does not exist or is not readable by the webserver in the phpsysinfo directory.

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.