1. 程式人生 > >PHP如何實現檔案寫入前追加,如依次寫入"我 愛 你",而實現的效果是"你愛我"

PHP如何實現檔案寫入前追加,如依次寫入"我 愛 你",而實現的效果是"你愛我"

<?php   //因為傳統的寫入是前追加或者覆蓋,所以我們需要先讀取拼接再寫入   $file = file_get_contents('hello.txt');//假設檔案裡面已有"愛我"兩個字   echo $file;   file_put_contents('hello.txt','你'.$file);//先取出,拼接完再重新寫入   結果:   你愛我