PHP fgets()ฟังก์ชั่น
❮ การอ้างอิงระบบไฟล์ PHPตัวอย่าง
อ่านหนึ่งบรรทัดจากไฟล์ที่เปิดอยู่:
<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>
ความหมายและการใช้งาน
ฟังก์ชัน fgets() ส่งกลับบรรทัดจากไฟล์ที่เปิดอยู่
ไวยากรณ์
fgets(file, length)
ค่าพารามิเตอร์
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 |
รายละเอียดทางเทคนิค
คืนมูลค่า: | อ่านบรรทัดเดียวจากไฟล์ว่าสำเร็จ FALSE บน EOF หรือข้อผิดพลาด |
---|---|
รุ่น PHP: | 4.0+ |
ตู้เซฟไบนารี: | ใช่ ใน PHP 4.3 |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
อ่านไฟล์ที่เปิดอยู่ทีละบรรทัด:
<?php
$file = fopen("test.txt","r");
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
❮ การอ้างอิงระบบไฟล์ PHP