<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. php語言

    php的file-put-contents()功能函數

    時間:2025-01-07 21:24:51 php語言 我要投稿
    • 相關推薦

    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使用ftp函數實現簡單上傳功能02-07

    php數學常用函數04-19

    PHP數據過濾函數01-26

    PHP類與構造函數07-01

    PHP常用函數匯總05-22

    PHP常用函數總結03-10

    PHP函數知識總結04-24

    PHP基本函數介紹02-07

    php常用的系統函數05-05

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人