note 39183 added to function.fgets
| From: | php-general at lists dot php dot net | Date: | Tue, 20 Jan 2004 01:45:19 +0000 |
| Subject: | note 39183 added to function.fgets | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63855@lists.php.net to get a copy of this message | ||
If you are using a version of PHP prior to 4.3, but need the functionality that
auto_detect_line_endings offers, try this function as an alternative:
/**
* GetLine
* Obtain the next line in a given file by reading each character
* until a \r or \n is reached.
*
* @param file a handle returned from fopen for the file.
* @return string the next line in the file.
*/
function getLine($file)
{
// iterate over each character in line.
while ($character = fgetc($file))
{
// check for end of line.
if (($character == "\n") or ($character == "\r"))
{
// end of line, so stop reading.
break;
} else {
// not EOL, so append to buffer.
$buffer .= $character;
}
}
// return the line buffer.
return $buffer;
}
----
Manual Page -- http://www.php.net/manual/en/function.fgets.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39183
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39183&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39183&report=yes
Search -- http://master.php.net/manage/user-notes.php