note 39384 added to function.fgets

From: Date: Tue, 27 Jan 2004 02:47:33 +0000
Subject: note 39384 added to function.fgets
Groups: php.notes 
Request: Send a blank email to php-notes+get-64220@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.fgets.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39384 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39384&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39384&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64220) next »