| 本文介紹下,php中有關ob_get_contents()、ob_end_clean()、ob_start()函數的具體用法,有需要的朋友參考下吧。 php緩衝相關函數:ob_get_contents();ob_end_clean();ob_start() 使用ob_start()把輸出那同輸出到緩衝區,而不是到瀏覽器。然後用ob_get_contents得到緩衝區的資料。 ob_start()在伺服器開啟一個緩衝區來儲存所有的輸出。因此,在任何時候使用echo ,輸出都將被加入緩衝區中,直到程式運行結束或者使用ob_flush()來結束。然後在伺服器中緩衝區的內容才會發送到瀏覽器,由瀏覽器來解析顯示。 函數ob_end_clean 會清除緩衝區的內容,並將緩衝區關閉,但不會輸出內容。此時得用一個函數ob_get_contents()在ob_end_clean()前面來獲得緩衝區的內容。這樣的話,能將在執行ob_end_clean()前把內容儲存到一個變數中,然後在ob_end_clean()後面對這個變數做操作。 例子: ';echo $buf2;?> 下面來看,ob_get_contents (PHP 4, PHP 5)ob_get_contents -- Return the contents of the output bufferDescriptionstring ob_get_contents ( void ) This will return the contents of the output buffer or FALSE, if output buffering isn't active. See also ob_start() and ob_get_length(). if you use ob_start with a callback function as a parameter, and that function changes ob string (as in example in manual) don't expect that ob_get_contents will return changed ob.it will work as you would use ob_start with no parameter at all. So don't be confused.transfer image, another method (alternative to fsockopen or function socket) : server(192.168.0.1)makeimage.php naturally you can transfer whichever thing and not only images ob_get_clean (PHP 4 >= 4.3.0, PHP 5)ob_get_clean -- Get current buffer contents and delete current output bufferDescriptionstring ob_get_clean ( void ) This will return the contents of the output buffer and end output buffering. If output buffering isn't active then FALSE is returned. ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean(). 例1:ob_get_clean()的簡單樣本 輸出: string(11) "hello world" 例2,ob_start() and ob_get_contents().Notice that the function beneath does not catch errors, so throw in an @ before those ob_* callsRunning PHP4 < 4.3.0, you can simply add the following to use the function anyway: |