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