Re: A problem with fgets()
| From: | Chris | Date: | Fri, 30 May 2008 01:21:45 +0000 |
| Subject: | Re: A problem with fgets() | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274852@lists.php.net to get a copy of this message | ||
> 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 number of bytes you tell it to start at.
Then fgets reads the rest of the line.
A file that looks like this:
(numbers are the "bytes" for ease of explanation)
123456789
is going to be different to a file that looks like this:
1234
56
789
and if you tell me you want to start at "byte 5", then in file 1, that's
the middle - in file 2 that's the start of the second line (#4 is a
newline char :P).
--
Postgresql & php tutorials
http://www.designmagick.com/