PHP fgetcsv() 함수
❮ PHP 파일 시스템 참조예시
열려 있는 CSV 파일에서 한 줄을 읽고 출력합니다.
<?php
$file = fopen("contacts.csv","r");
print_r(fgetcsv($file));
fclose($file);
?>
정의 및 사용
fgetcsv() 함수는 CSV 필드 를 확인하여 열린 파일에서 한 줄을 구문 분석합니다 .
팁: fputcsv() 함수 도 참조하십시오 .
통사론
fgetcsv(file, length, separator, enclosure)
매개변수 값
Parameter | Description |
---|---|
file | Required. Specifies the open file to return and parse a line from |
length | Optional. Specifies the maximum length of a line. Must be greater than the longest line (in characters) in the CSV file. Omitting this parameter (or setting it to 0) the line length is not limited, which is slightly slower. Note: This parameter is required in versions prior to PHP 5 |
separator | Optional. Specifies the field separator. Default is comma ( , ) |
enclosure | Optional. Specifies the field enclosure character. Default is " |
escape | Optional. Specifies the escape character. Default is "\\" |
기술적 세부 사항
반환 값: | 성공 시 CSV 필드가 있는 배열, 유효하지 않은 파일 이 제공된 경우 NULL, 기타 오류 및 EOF 시 FALSE |
---|---|
PHP 버전: | 4.0+ |
바이너리 금고: | 예, PHP 4.3.5에서 |
PHP 변경 로그: | PHP 5.3 - 이스케이프 매개변수 추가 |
더 많은 예
예시
CSV 파일의 전체 내용을 읽고 출력합니다.
<?php
$file = fopen("contacts.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file));
}
fclose($file);
?>
❮ PHP 파일 시스템 참조