PHP의는 fgets () 함수
정의 및 사용
는 fgets () 함수는 열린 파일에서 행을 반환합니다.
는 fgets () 함수는 지정된 길이의 끝에 도달하거나 (제 1 온다 중) 파일 (EOF)을 읽고, 정지 새로운 라인으로 돌아갑니다.
실패하면 함수는 FALSE를 반환합니다.
문법
fgets(file,length)
参数 | 描述 |
---|---|
file | 必需。规定要读取的文件。 |
length | 可选。规定要读取的字节数。默认是 1024 字节。 |
예 1
<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>
가 출력 위의 코드 :
Hello, this is a test file.
예 2
라인으로 파일 라인을 읽기 :
<?php
$file = fopen("test.txt","r");
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
$file = fopen("test.txt","r");
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
가 출력 위의 코드 :
Hello, this is a test file.
There are three lines here.
This is the last line.
There are three lines here.
This is the last line.
PHP 파일 시스템 참조 설명서를 완료