note 39384 deleted from function.fgets by nlopess
| From: | nlopess@php.net | Date: | Mon, 01 Mar 2004 14:25:56 +0000 |
| Subject: | note 39384 deleted from function.fgets by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66048@lists.php.net to get a copy of this message | ||
Note Submitter: horror@hack.gr
----
This code fixes a small bug in the previous one for getting a new line. In the previous code if you
put a <br> after each return, you will get 2 line feeds for each line for normal files. On the
other hand, if you make a new line every 2nd return, you might be wrong if the file has only
cr's and no lf's or the opposite. This one does the check :)
<?php
function getline ($handle) {
while (!feof($handle)) {
$char = fgetc($handle);
if (($char == "\n") or ($char == "\r")) {
$char2 = fgetc($handle);
if ((($char2 == "\n") or ($char2 == "\r")) and ($char == $char2)) {
fseek ($handle,-1,SEEK_CUR);
}
break;
}
else {
$buffer .= $char;
}
}
return $buffer;
}
?>