PHP New Line will not work

Hey. I am trying to create code that first reads the existing contents of a file and then adds a new line of code to a new line, but the code I use just adds it to new text on an existing line instead of a new line ...

Here is the code I'm using:

<?php

$id = $_GET['id'];

$userfile = "user1.txt";
$fo = fopen($userfile, 'r') or die("can't open favourites file");
$currentdata = fread($fo, filesize($userfile));
fclose($fo);
$fw = fopen($userfile, 'w') or die("can't open favourites file");
$currentprocessed = "$currentdata\n";
fwrite($fw, $currentprocessed);
fwrite($fw, $id);
fclose($fw);
?>

I tried a number of different ideas, but nothing worked, any help would be appreciated.

+3
source share
3 answers

Instead of adding a \nconstant concatenation PHP_EOL, which is always the correct newline for the current platform.

, , . , "" Windows unix.

+3

Unix/Linux
\n

DOS/Windows
\r\n

Invalid
\r \n\r


PHP_EOL php. - .

+8

. ? , - Notepad ( .txt) escape- "\n\r". .txt , , Notepad ++, Atom ( ) , .

0

Source: https://habr.com/ru/post/1749791/


All Articles