Re: fgets question
| From: | Monte Ohrt | Date: | Wed, 14 Aug 2002 18:01:24 +0000 |
| Subject: | Re: fgets question | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-112565@lists.php.net to get a copy of this message | ||
That was my first thought but that wasn't it. To be sure, I urlencoded the file and looked at it:
1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A
No extra newlines that I could see.
FYI, if you run the program from the command line, you have to pipe the output to a pager or you will not see the last (extra) line since there is no newline character.
I'm using PHP 4.2.2 on Solaris sparc.
Monte
Kevin Stone wrote:
The only explaination is that 'vi' is putting an extra line in there that you're not seeing. -Kevin ----- Original Message ----- From: "Monte Ohrt" <monte@ispi.net> To: <php-general@lists.php.net> Sent: Wednesday, August 14, 2002 11:05 AM Subject: [PHP] fgets questionHi, I have a question about fgets(), it seems to pick up an extra line at the end of a text file. example, I open a new file named "test" with the vi editor and make it 8 lines long like so (showing newlines as \n): 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n I create this PHP program and run it: <?php $fd = fopen ("test","r"); while (!feof ($fd)) {$buffer = fgets($fd, 4096); echo "buffer is $buffer";} fclose ($fd); ?> 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? TIA Monte -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php