PHP首次将字符串写入新行而不是文件末尾

lom*_*mse 2 php codeigniter

使用Codeigniter函数write_file(),我可以写入这样的现有文件:

write_file("path_to_file", "String four"."\n", "a+");
Run Code Online (Sandbox Code Playgroud)

假设我已经有这样的文件:

String one
String two
String three
Run Code Online (Sandbox Code Playgroud)

有了write_file("path_to_file", "String four"."\n", "a+"),我第一次写文件时有以下输出:

String one
String two
String three String four
Run Code Online (Sandbox Code Playgroud)

关于如何 第一次将String 4写入新行的任何想法?如下图所示:

String one
String two
String three 
String four
Run Code Online (Sandbox Code Playgroud)

谢谢.

Clé*_*let 5

不太了解这个write_file()函数,但鉴于你所说的,这应该工作:

write_file("path_to_file", "\n"."String four"."\n", "a+")
Run Code Online (Sandbox Code Playgroud)