テキスト追加の例
txt.txt
このファイルはファイルプットコンテンツで書き換えられます
どうぞ
ご確認ください
file_put.php
$file = 'txt.txt';
// ファイルをオープンして既存のコンテンツを取得します
$current = file_get_contents($file);
echo $current;
$current .= "\n"."この行は追加ファイルです。\n";
// 結果をファイルに書き出します
file_put_contents($file, $current);
上記実行後のtxt.txt
このファイルはファイルプットコンテンツで書き換えられます
どうぞ
ご確認ください
この行は追加ファイルです。
テキスト上書きの例(file_put.php)
<?php
$file = 'txt.txt';
$new_txt .= "新規記述です\n";
// 結果をファイルに書き出します
file_put_contents($file, $new_txt);
実行後のtxt.txt
新規記述です
以上。
応用すれば条件によってファイルの出力や取得を使って色々出来そう。