note 109339 added to function.stream-get-line
| From: | Anonymous | Date: | Sun, 08 Jul 2012 03:35:49 +0000 |
| Subject: | note 109339 added to function.stream-get-line | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189066@lists.php.net to get a copy of this message | ||
WARNING:
Specifying a length of 0 does NOT give you an infinite length, contrary to what the documentation
might suggest. Instead, setting a length of 0 just makes the function default to a length of 8192.
To be precise, it gets the value PHP_SOCK_CHUNK_SIZE (8192) in ext/standard/streamsfuncs.c.
So, let's say you're trying to read ALL data until you reach a "\x03" (decimal
3) byte. How do you GUARANTEE that this is the case? Well, there's no way! The only thing you
can do stream_get_lin() into a "master" string, then fseek() backwards by 1 character,
then fgetc() and verify that it's "\x03". If you don't see a "\x03",
it means that stream_get_line() has aborted after 8192 bytes and before hitting "\x03",
and you'll have to call it again. Keep appending the return values to a "master"
string until you hit a "\x03" or EOF... That's the ONLY way to properly build a
string that contains EVERYTHING until the character you're looking for.
----
Server IP: 69.147.83.197
Probable Submitter: 176.10.245.112
----
Manual Page -- http://www.php.net/manual/en/function.stream-get-line.php
Edit -- https://master.php.net/note/edit/109339
Del: integrated -- https://master.php.net/note/delete/109339/integrated
Del: useless -- https://master.php.net/note/delete/109339/useless
Del: bad code -- https://master.php.net/note/delete/109339/bad+code
Del: spam -- https://master.php.net/note/delete/109339/spam
Del: non-english -- https://master.php.net/note/delete/109339/non-english
Del: in docs -- https://master.php.net/note/delete/109339/in+docs
Del: other reasons-- https://master.php.net/note/delete/109339
Reject -- https://master.php.net/note/reject/109339
Search -- https://master.php.net/manage/user-notes.php