问题
Using Codeigniter function write_file()
, I can write to an existing file like this:
write_file("path_to_file", "String four"."\n", "a+");
Assume I already have a file like this:
String one
String two
String three
With write_file("path_to_file", "String four"."\n", "a+")
, I have the ouput below when writing to file for the first time:
String one
String two
String three String four
Any idea about how I can write String four to new line for the first time? Like shown below:
String one
String two
String three
String four
Thanks.
回答1:
Not knowing much about this write_file() function, but given what you said, this should work :
write_file("path_to_file", "\n"."String four"."\n", "a+")
回答2:
Try adding new line before String four:
write_file("path_to_file", "\nString four\n", "a+")
来源:https://stackoverflow.com/questions/18322558/php-write-string-to-new-line-for-the-first-time-and-not-at-the-end-of-file