Feof funksiyası
feof funksiyası oxu zamanı faylın sonuna catilib-catilmadigini yoxlayir. O, bir parametr qebul edir - fopen funksiyası terefinden ugurla acilmis fayl gostericisi. Faylın sonuna catilmissa true, eks halda ise false qaytarir.
Sintaksis
feof(resource $handle): bool
Numune
Oxu zamanı faylın sonuna catilib-catilmadigini yoxlayaq:
<?php
$file = fopen('test.txt', 'r');
while (!feof($file)) {
echo fgets($file);
}
fclose($file);
?>
Bu numunede faylın sonuna catana qeder onu setir-setir oxuyuruq.
Numune
Fayl acildiqdan sonra fayl gostericisinin veziyyetini yoxlayaq:
<?php
$file = fopen('empty.txt', 'r');
var_dump(feof($file));
fclose($file);
?>
Bos fayl ucun kodun icra neticesi:
true
Numune
Fayl acarken xetanın emalı:
<?php
$file = @fopen('nonexistent.txt', 'r');
if ($file === false) {
echo "File not found";
} else {
while (!feof($file)) {
echo fgets($file);
}
fclose($file);
}
?>
Fayl movcud olmadıqda kodun icra neticesi:
'File not found'