note 8377 added to fgets
| From: | mbabcock at fibrespeed dot net | Date: | Sat, 09 Sep 2000 04:28:00 +0000 |
| Subject: | note 8377 added to fgets | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-4609@lists.php.net to get a copy of this message | ||
A common mistake is given in the previous example. That is, if the string you're searching for
occurs over a boundary (in this case, of 4k). For example, if the word "hello" were found
starting at the 8th character and I read 10 characters, "hello" would not be found. If I
read the next 10 characters, "hello" would again not be found (although "llo"
would be).
One solution is to always increment your buffer by BUFFER_SIZE - (SEARCH_STR_LEN-1). That will make
sure your search string shows up.
<PRE>
$i = 0;
$search = "hello";
(loop while not eof ...)
$i += 4096 - (strlen($search) - 1);
http://www.php.net/manual/function.fgets.php