使用笨功能write_file()
年底新生產線,我可以寫一個像這樣的現有文件:PHP寫字符串的第一次,而不是在文件
write_file("path_to_file", "String four"."\n", "a+");
假設我已經有一個這樣的文件:
String one
String two
String three
隨着write_file("path_to_file", "String four"."\n", "a+")
,我有寫入文件首次在下面的輸出中:
String one
String two
String three String four
有關我如何寫字符串四第一次到新線的任何想法?如下圖所示:
String one
String two
String three
String four
謝謝。
你可以首先檢查該文件是空的;如果是,只需寫下行。如果不是,請添加新行和您的內容。 –