- 相關推薦
php的file-put-contents()功能函數
php file_put_contents()功能函數(集成了fopen、fwrite、fclose) ,需要的朋友可以參考下。就跟隨百分網小編一起去了解下吧,想了解更多相關信息請持續關注我們應屆畢業生考試網!
命令:file_put_contents();
命令解析:file_put_contents (PHP 5)
file_put_contents -- 將一個字符串寫入文件
說明:
int file_put_contents ( string filename, string data [, int flags [, resource context]] )
和依次調用 fopen(),fwrite() 以及 fclose() 功能一樣。
參數 data 可以是數組(但不能為多維數組),這就相當于 file_put_contents($filename, join('', $array))
自 PHP 5.1.0 起,data 參數也可以被指定為 stream 資源,這里 stream 中所保存的緩存數據將被寫入到指定文件中,這種用法就相似于使用 stream_copy_to_stream() 函數。
參數
filename
要被寫入數據的文件名。
data
要寫入的數據。類型可以是 string,array 或者是 stream 資源(如上面所說的那樣)。
flags
flags 可以是 FILE_USE_INCLUDE_PATH,FILE_APPEND 和/或 LOCK_EX(獲得一個獨占鎖定),然而使用 FILE_USE_INCLUDE_PATH 時要特別謹慎。
context
一個 context 資源。
寫入代碼(代碼本身無錯,但陰差陽錯學會了它的另一個功能):
復制代碼 代碼如下:
<?php
$contents = "這是使用file_put_contents寫入的內容";
$contents2 = array("這是使用","file_put_contents","命令寫入的內容");
file_put_contents("html/caceh.txt",$contents);
file_put_contents("html/cache2.txt",$contents2);
?>
代碼分析:打算使用file_put_contents命令向cache.txt,cache2.txt這兩個文件中寫入字符串。
結果:在html文件目錄內新增了caceh.txt文件,你懂了吧————
謹記:file_put_contents()函數集成了fopen(),fwrite(),fclose()三種函數,此例中新建的文件就是fopen()的功能.
【php的file-put-contents()功能函數】相關文章:
PHP函數知識總結09-29
PHP數組函數知識10-24
PHP函數的區別及用法10-27
PHP類與構造函數07-01
簡單PHP數組函數介紹09-26
php摘要生成函數詳解09-02
PHP常用的文件操作函數10-17
PHP網絡操作函數講解07-23
2017PHP5函數大全10-24
php的字符串常用函數06-15