相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
PHP中file_put_contents追加和換行的實現(xiàn)方法
在PHP的一些應(yīng)用中需要寫日志或者記錄一些信息,這樣的話??梢允褂胒open(),fwrite()以及 fclose()這些進行操作。也可以簡單的使用file_get_contents()和file_put_contents().
file_put_contents()寫文件。默認的是重新寫文件,也就是會 替換原先的內(nèi)容。追加的話使用參數(shù)FILE_APPEND.
以追加形式寫入內(nèi)容 當(dāng)設(shè)置 flags 參數(shù)值為 FILE_APPEND 時,表示在已有文件內(nèi)容后面追加內(nèi)容的方式寫入新數(shù)據(jù):
FILE_APPEND:在文件末尾以追加的方式寫入數(shù)據(jù)
int file_put_contents ( string filename, string data [, int flags [, resource context]] ) file_put_contents("log.txt", "Hello world everyone.", FILE_APPEND);