Good morning everyone. I just started in php so please forgive my ignorance.
I'm trying to append $newflyline to a $flyline that contains $oldflyline then echo fgets($file). My problem is fgets is reading to the eof not the expected eol. Guess I'm missing the <lf> thing?
Here's what I have:
This is what I'm getting running it 4 times;Code:$flyline = 'testscript.txt'; $oldflyline = file_get_contents($flyline); $newflyline = "new line<lf>"; //- - - open - write - close flyline - - - - - - - - - - - - - - - - - - - - - $flockfile = fopen($flyline, 'w+') or exit('Unable to open file!'); if (flock($flockfile, LOCK_EX)) { fwrite($flockfile, $newflyline); fwrite($flockfile, $oldflyline); flock($flockfile, LOCK_UN);} else echo "oops! Try again, no lock on file"; fclose($flockfile); //- - - table display - - - - - - - - - - $file = fopen($flyline,'r') or exit('Unable to open file!'); $i="1"; while ($i <= 2){ echo fgets($file); $i++; }fclose($file);
new linenew linenew linenew line
what I want is to control the number of lines displayed with while($i<=2)
new line
new line



Reply With Quote

Bookmarks