note 85193 modified in function.stream-get-line by felipe

From: Date: Wed, 20 Aug 2008 21:59:04 +0000
Subject: note 85193 modified in function.stream-get-line by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143687@lists.php.net to get a copy of this message
If the "ending" is a string, there are cases where the function doesn't return the correct value for the first time it is called. Don't be shocked if you find it returning a string value of upto "length" that includes the "ending". (See bug #44607) If the "ending" is just a single character, the function would always work correctly. ("\n" is a single character) Temporarily, until this is fixed, the below function can be used: <?php function istream_get_line(&$fp, $length, $end) { $current = ftell($fp); $str = fread($fp, $length); $i = strpos($str, $end); if ($i === FALSE) { return $str; } else { fseek($fp, $current + $i + strlen($end)); return substr($str, 0, $i); } } ?> --was-- If the "ending" is a string, there are cases where the function doesn't return the correct value for the first time it is called. Don't be shocked if you find it returning a string value of upto "length" that includes the "ending". (See bug #44607) If the "ending" is just a single character, the function would always work correctly. ("\n" is a single character) Temporarily, until this is fixed, the below function can be used: function istream_get_line(&$fp, $length, $end) { $current = ftell($fp); $str = fread($fp, $length); $i = strpos($str, $end); if ($i === FALSE) { return $str; } else { fseek($fp, $current + $i + strlen($end)); return substr($str, 0, $i); } } http://php.net/manual/en/function.stream-get-line.php

« previous php.notes (#143687) next »