Re: [PHP] A problem with fgets()

2008-06-05 Thread Usamah M. Ali
Well, finally found an explanation and a solution: calling fgets() twice. Because if there's no length limit supplied (and it's not EOF) when calling the function, it continues reading until it finds the first newline character. So calling fgets() again will ensure that it will read from the

RE: [PHP] A problem with fgets()

2008-06-04 Thread Ford, Mike
On 30 May 2008 02:56, Usamah M. Ali advised: So you're confirming that fgets() doesn't necessarily read a whole line? This user note existed on the manual's page of fgets() since 2004 and nobody deleted it or commented about: rstefanowski at wi dot ps dot pl 12-Aug-2004 09:03 Take note

[PHP] A problem with fgets()

2008-05-29 Thread Usamah M. Ali
Hello, I have a function that picks up a random entry from a file consisting of city names, each name on a separate line. The random value is generated by rand() before fseek()ing to the position determined by it. The problem is that when using fgets() to get a random line, it returns a part of

Re: [PHP] A problem with fgets()

2008-05-29 Thread Chris
Usamah M. Ali wrote: Hello, I have a function that picks up a random entry from a file consisting of city names, each name on a separate line. The random value is generated by rand() before fseek()ing to the position determined by it. The problem is that when using fgets() to get a random

Re: [PHP] A problem with fgets()

2008-05-29 Thread Usamah M. Ali
On Fri, May 30, 2008 at 3:38 AM, Chris [EMAIL PROTECTED] wrote: fseek doesn't go to the start of a line, it goes to a particular byte - so that's where the problem lies (not with fgets). There's no function (that I could see) which would go to the start of the line based on that offset (I

Re: [PHP] A problem with fgets()

2008-05-29 Thread Chris
I just need to figure out why when using fgets() with fseek() rand(), the script returns partial strings form the city names. Because fseek doesn't necessarily put you at the start of a line. It puts you anywhere (which could be the start, middle, 3 chars from the end) according to the

Re: [PHP] A problem with fgets()

2008-05-29 Thread Usamah M. Ali
On Fri, May 30, 2008 at 4:21 AM, Chris [EMAIL PROTECTED] wrote: I just need to figure out why when using fgets() with fseek() rand(), the script returns partial strings form the city names. Because fseek doesn't necessarily put you at the start of a line. It puts you anywhere (which could