PHP fgets() Fungsi
Referensi Sistem File PHPContoh
Baca satu baris dari file yang terbuka:
<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>
Definisi dan Penggunaan
Fungsi fgets() mengembalikan baris dari file yang terbuka.
Sintaksis
fgets(file, length)
Nilai Parameter
Parameter | Description |
---|---|
file | Required. Specifies the open file to return a line from |
length | Optional. Specifies the number of bytes to read. Reading stops when length-1 bytes have been reached, or when a new line occurs, or on EOF. If no length is specified, it reads until end of the line |
Detail Teknis
Nilai Kembali: | Satu baris dibaca dari file jika berhasil, FALSE pada EOF atau error |
---|---|
Versi PHP: | 4.0+ |
Biner Aman: | Ya, di PHP 4.3 |
Lebih Banyak Contoh
Contoh
Baca file yang terbuka, baris demi baris:
<?php
$file = fopen("test.txt","r");
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
Referensi Sistem File PHP