Reputation: 1104
I want to put a new line next to each URL that I save in a file. Therefore, I used the following code in php:
file_put_contents("test.txt", $url."\n", FILE_APPEND);
But when I open the file, all the URLs I put in the file is in one line and the new line hasn't been inserted.
Upvotes: 2
Views: 103
Reputation: 27382
You need to use \r\n
because \n
used to new line and \r
used for end of the current line.
Unix tends to use
\n
as a line separator; Windows tends to use\r\n
as a line separator and Macs (up to OS 9) used to use\r
as the line separator.
Upvotes: 2
Reputation: 27934
They are in different lines, but you are using the UNIX newline format, therefore some Windows programs like Notepad will not understand this right.
Use \r\n
instead of just \n
, or get a better text editor.
Upvotes: 1