note 54776 deleted from function.fgets by betz

From: Date: Fri, 16 Sep 2005 09:29:58 +0000
Subject: note 54776 deleted from function.fgets by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-95284@lists.php.net to get a copy of this message
Note Submitter: intox at cariboucrew dot com ---- In response to Allen: "The original example could be coded as: <?php $handle = fopen("/tmp/inputfile.txt", "r"); while (!feof($handle)) { $buffer = fgets($handle, 4096); if (!feof($handle)) { echo $buffer; } } fclose($handle); ?>" This is fine except that this code checks for EOF twice. If there is no newline at the end of a file the very last line will not be parsed even if there is data on that line. This is better yet: <?php $handle = fopen("/tmp/inputfile.txt", "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); echo $buffer; } } fclose($handle); ?> IntoX

« previous php.notes (#95284) next »