Ledeniqt
Ledeniqt

Reputation: 37

Where am I wrong? Writing to file PHP

while (!feof($file1) && $linecount++<$requiredLines) { 

        $line = stream_get_line($file1, $filesize, PHP_EOL ); 

        fwrite($file2,$line);
    }

How to make it to write every line on new line? Like this:

line1
line2
line3

I have tried this way but then i do not fulfill the condition:

while (!feof($file1) && $linecount++<$requiredLines) { 

        $line = stream_get_line($file1, $filesize, '\n' ); 

        fwrite($file2,$line);
    }

My idea is to write 10 or more lines but to be on new line every time.

Upvotes: 0

Views: 31

Answers (1)

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137467

Add the line terminator yourself:

fwrite($file2, $line."\n");

Note that escape characters are not interpreted in single-quote strings, and you must use a double-quote string.

Upvotes: 3

Related Questions