Re: fgets question

From: Date: Wed, 14 Aug 2002 18:28:51 +0000
Subject: Re: fgets question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-112571@lists.php.net to get a copy of this message
Hi Monte, > Hi, I have a question about fgets(), it seems to pick up an extra line > at the end of a text file. ... > 8\n ... > Here is the output (showing newlines as \n): > buffer is 1\n > buffer is 2\n > buffer is 3\n > buffer is 4\n > buffer is 5\n > buffer is 6\n > buffer is 7\n > buffer is 8\n > buffer is > My question, why is there an extra line? Or in other words, how do I get > this to loop exactly 8 times if there are only 8 lines? The answer is that there isn't an 'extra' line, there are as many as you put/PHP reads! The question to ask is: how does a stream file end? Answer: with an EOF character (not an LF). Lines in a (*nix) stream file are separated by LF or \n character, therefore there is a ninth 'line' (of absolutely nothing) between the last LF and the EOF. Take out that last \n and things should work the way you want. Regards, =dn

« previous php.general (#112571) next »