php-file_put_contents() 函數

定義和用法

file_put_contents() 函數把一個字符串寫入文件中

語法

file_put_contents(file,data,mode,context)

參數解析

參數 描述
file 必需。規定要寫入數據的文件。若是文件不存在,則建立一個新文件。
data 可選。規定要寫入文件的數據。能夠是字符串、數組或數據流。
mode

可選。規定如何打開/寫入文件。可能的值:php

  • FILE_USE_INCLUDE_PATH數組

  • FILE_APPENDide

  • LOCK_EX函數

context

可選。規定文件句柄的環境。spa

context 是一套能夠修改流的行爲的選項。若使用 null,則忽略。orm

返回值

該函數將返回寫入到文件內數據的字節數

示例

<?php
            $filename = "ceshi/2.txt";
            $content = file_get_contents($filename);
            // highlight_string($content);
            highlight_file($filename);

            file_put_contents($filename,$content."xinde");
?>

輸出

dsfsdfsafsdfdsxindexindexinde 34
相關文章
相關標籤/搜索