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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php