note 39913 modified in function.fseek by aidan

From: Date: Tue, 29 Jun 2004 18:23:01 +0000
Subject: note 39913 modified in function.fseek by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72119@lists.php.net to get a copy of this message
I think the function should be as following to deal any combination of cr & lf, no matter the line ends by cr, lf, cr-lf or lf-cr: <?php function getline ($handle) { while (!feof($handle)) { $char = fgetc($handle); if (($char == "\n") or ($char == "\r")) { $char2 = fgetc($handle); if (($char2 != "\n") && ($char2 != "\r")) { fseek ($handle,-1,SEEK_CUR); } break; } else { $buffer .= $char; } } return $buffer; } ?> --was-- I think the function should be as following to deal any combination of cr & lf, no matter the line ends by cr, lf, cr-lf or lf-cr: function getline ($handle) { while (!feof($handle)) { $char = fgetc($handle); if (($char == "\n") or ($char == "\r")) { $char2 = fgetc($handle); if (($char2 != "\n") && ($char2 != "\r")) { fseek ($handle,-1,SEEK_CUR); } break; } else { $buffer .= $char; } } return $buffer; } http://php.net/manual/en/function.fseek.php

« previous php.notes (#72119) next »