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 |
기술적 세부 사항
반환 값: | 성공 시 파일에서 한 줄 읽기, EOF 또는 오류 시 FALSE |
---|---|
PHP 버전: | 4.0+ |
바이너리 금고: | 예, PHP 4.3에서 |
더 많은 예
예시
열린 파일을 한 줄씩 읽기:
<?php
$file = fopen("test.txt","r");
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
❮ PHP 파일 시스템 참조