Results 1 to 2 of 2

Thread: writing to file including linefeed

  1. #1
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy writing to file including linefeed

    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:
    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);
    This is what I'm getting running it 4 times;
    new linenew linenew linenew line
    what I want is to control the number of lines displayed with while($i<=2)
    new line
    new line
    Last edited by djr33; 12-13-2011 at 06:35 PM. Reason: add something...

  2. #2
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    "new line<br>\n";
    was the answer - got it now

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •