1,file_put_contents()函數
2,使用PHP內置緩存機制實現頁面靜態化:output_buffering
php中output_buffering內置函數,簡稱ob函數,主要會用到的下面幾個:
- ob_start #打開輸出控制緩沖
- ob_get_contents #獲取輸出緩沖區內容
- ob_clean #清空輸出緩沖區
- ob_get_clean #獲取當前緩沖區內容,然后清空當前輸出緩沖區
1
2
3
4
5
6
7
8
|
<?php // 開啟輸出緩沖控制 ob_start(); echo 'hello world' ; // 輸出點兒內容 // 獲取緩沖區的內容,然后寫入到1.txt中 file_put_contents ( '1.txt' ,ob_get_contents()); |
上面代碼會在目錄下,生成一個1.txt文件,內容就是:hello world。
清空緩沖區,內容就不會在終端顯示了:
1
2
3
4
5
6
7
8
9
10
11
|
<?php // 開啟輸出緩沖控制 ob_start(); echo 'hello world' ; // 輸出點兒內容 // 獲取緩沖區的內容,然后寫入到1.txt中 file_put_contents ( '1.txt' ,ob_get_contents()); ob_clean(); // 清空輸出緩沖區 // 注意,瀏覽器就不會顯示"hello world"了 |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://blog.csdn.net/github_26672553/article/details/72871744