Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] write_file() - How to insert a newline character?
#1

[eluser]Alexandro Corrêa[/eluser]
Hi Everyone!

I need write some information to a text file. Each information should stay in one different line. When I insert '\n' it is printed as text, not a newline.

Code:
$log1 = "Info 1\n";
$log2 = "Info 2\n";

write_file('.\app\logs\envio.txt', $log1, 'a');
write_file('.\app\logs\envio.txt', $log2, 'a');

Using this, the file is written, but the result is in just one line, not two lines with the information. I'm breaking my head to find a solution but until now I couldn't...

Thanks for your help!
Alex.
#2

[eluser]_TubbZ_[/eluser]
I maybe wrong but on windows I think you have to do \r\n to create a newline in a file.

EDIT:

guessing from your variable names are you creating a log file? You maybe better off using CI's log_message() method.
#3

[eluser]Alexandro Corrêa[/eluser]
Thanks TubbZ! But \r\n don't work too... it seems that write_file consider all characters on variable as text-only.
#4

[eluser]Alexandro Corrêa[/eluser]
I found a solution! The code was right, I don't know why, but I've excluded the file 'envio.txt' and try to write the file again, then php created the new file and wrote the information correctly. Maybe the format of file created initially was the problem.




Theme © iAndrew 2016 - Forum software by © MyBB