Reputation: 43
I'm working with PHP, and I would like to create a line-break in my .txt database after every input.
Is this even possible and how?
Please help, I have tried /n
and <br>
but these won't work.
Some code:
fwrite($handle,$artikelnummer);
fwrite($handle,$newData);
Between these two I want a linebreak
Upvotes: 0
Views: 79
Reputation: 1894
Use :
fwrite($file, $yourData . "\n");
Don't use '\n'
as PHP will not recognize the escape sequence then.
If you want to be platform independent use PHP_EOL
which outputs \r\n
or \n
depending on the OS. Its a predefined constant. Look here.
If you want an empty line after writing a line :
fwrite($file, $yourData . PHP_EOL . PHP_EOL);
Upvotes: 2
Reputation: 17721
Something like this?
fwrite($handle, $artikelnummer);
fwrite($handle, "\n");
fwrite($handle, $newData);
As Shikhar Bhardwaj pointed out, you could use PHP_EOL, instead of "\n", if you want to be completely OS platform independent...
UPDATE: If what you expect is one empty line between lines, you have to write 2 newlines...:
fwrite($handle, $artikelnummer);
fwrite($handle, PHP_EOL . PHP_EOL);
fwrite($handle, $newData);
Upvotes: 1
Reputation: 1057
You have to use Backslash and letter n in double-quotes:
fwrite($handle, "This is my text with \n a linebreak");
Upvotes: 1