Linefeed with fputs in php
If you want to collect data from a text file with fgets, lines should be seperated by chr13,chr10 or in hex 0D 0A.
Unfortunately it is not easy as it seems to write such a file with fputs. I've checked out the following combinations in PHP4.3.2. The comments
refer to the write mode(w). In append mode (a) the output is different. I haven't found any combination that always puts out chr13,chr10.
This all refers to Windows. I haven't checked behaviour under Linux. It might be different because Linux uses only 0D as linefeed.
$f=fopen('test.txt','w'); // or 'a' as append
fputs ($f,'testa'); //nothing
fputs ($f,'testc'.chr(13)); //13
fputs ($f,'testd'.chr(10)); //13 append: 13,10
fputs ($f,'teste'.chr(10).chr(13)); //13,10 (!) append: 13,10,13
fputs ($f,'testf'.chr(13).chr(10)); //13,13 append: 13,13,10
fputs ($f,"testg\n"); //13 append:13,10
fputs ($f,'testh\n'); // '\n'
fputs ($f,"testi\n\n"); //13,10 append: 13,10,13,10
fputs ($f,"testj\r\n"); //13,10 append: 13,13,10
fputs ($f,"testk\n\r"); //13,10 append: 13,10,13
fputs ($f,"testl\r"); //13
fputs ($f,"testz");
So, confused? Me, too.
Radiovibrations.com ->
PHP blog