PHP/File Directory/feof
Версия от 13:37, 26 мая 2010; (обсуждение)
Содержание
Counting lines in a file
<source lang="html4strict">
<?php $lines = 0; if ($fh = fopen("data.txt","r")) {
while (! feof($fh)) { if (fgets($fh)) { $lines++; } }
} print $lines; ?>
</source>
feof.php
<source lang="html4strict">
<?php
$fh = fopen("/home/www/data/users.txt", "rt"); while (!feof($fh)) echo fgets($fh); fclose($fh);
?>
</source>
Reading lines from a file
<source lang="html4strict">
<?php $fh = fopen("orders.txt","r") or die($php_errormsg); while (! feof($fh)) {
$s = fgets($fh,256); process_order($s);
} fclose($fh) or die($php_errormsg); ?>
</source>
Read till the end of a file
<source lang="html4strict">
<?
$huge_file = fopen("VERY_BIG_FILE.txt", "r"); while (!feof($huge_file)) { print fread($huge_file, 1024); } fclose($huge_file);
?>
</source>