語法 file_put_contents(file,data,mode,context)

file 必需。規定要寫入數據的文件。如果文件不存在,則創建一個新文件。
data 可選。規定要寫入文件的數據。可以是字符串、數組或數據流。
mode 可選。規定如何打開/寫入文件。可能的值:
FILE_USE_INCLUDE_PATH
FILE_APPEND
LOCK_EX
context 可選。規定文件句柄的環境。是一套可以修改流的行為的選項。若使用null,則忽略。


例子
<?php
echo file_put_contents("test.txt","Hello World. Testing!");
?>
輸出:
26

 

Example #1 Simple usage example

<?php
$file = 'people.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "John Smith\n";
// Write the contents back to the file
file_put_contents($file, $current);
?>

arrow
arrow
    全站熱搜

    stockwfj3 發表在 痞客邦 留言(0) 人氣()