why does fgets() return 1 on empty lines

229 views
Skip to first unread message

Jochen Daum

unread,
Aug 3, 2008, 8:15:37 PM8/3/08
to PHPUG
Hi,

I'm writing a small configuration file parser.  A small problem is that on all empty lines fgets returns string "1". My lines end with \n (unix style). Is this intentional?

Jochen

Boyd

unread,
Aug 3, 2008, 8:39:48 PM8/3/08
to NZ PHP Users Group
your line breaks take up 1 byte and that's what fget's returns:

http://nz.php.net/manual/en/function.fgets.php

Jochen Daum

unread,
Aug 3, 2008, 8:57:43 PM8/3/08
to nzp...@googlegroups.com
Hi,



It says:

Returns a string of up to length - 1 bytes read from the file pointed to by handle .

If an error occurs, returns FALSE.


How would I distinguish a line with "\n" and "1\n" then?


I'm confused, I can't find any mention of the length of the line being returned.


 Jochen

Boyd

unread,
Aug 3, 2008, 9:04:31 PM8/3/08
to NZ PHP Users Group
sorry, my answer was totally confused

On Aug 4, 12:57 pm, "Jochen Daum" <j...@automatem.co.nz> wrote:
> Hi,
>
>
>
> On Mon, Aug 4, 2008 at 12:39 PM, Boyd <eldritch.d...@gmail.com> wrote:
>
> > your line breaks take up 1 byte and that's what fget's returns:
>
> >http://nz.php.net/manual/en/function.fgets.php
>
> > On Aug 4, 12:15 pm, "Jochen Daum" <j...@automatem.co.nz> wrote:
> > > Hi,
>
> > > I'm writing a small configuration file parser.  A small problem is that
> > on
> > > all empty lines fgets returns string "1". My lines end with \n (unix
> > style).
> > > Is this intentional?
>
> It says:
>
> Returns a string of up to *length* - 1 bytes read from the file pointed to
> by *handle* .
>
> If an error occurs, returns *FALSE*.
Reply all
Reply to author
Forward
0 new messages