Php tutorial fgetcsv read csv file code
Function get_csv_contents ($ file_target ){
$ Handle = fopen ($ file_target, 'R ');
While ($ data = fgetcsv ($ handle, 1000 ,",")){
$ Num = count ($ data );
Echo "<p> $ num fields in line $ row: <br> n ";
$ Row ++;
For ($ c = 0; $ c <$ num; $ c ++ ){
Echo $ data [$ c]. "<br> n ";;
/* Echo getUTFString ($ data [$ c]) */
}
}
Fclose ($ handle );
}
Array fgetcsv (int handle [, int length [, string delimiter [, string enclosure])
Handle
A valid file pointer generated by fopen (), popen (), or fsockopen.
Length (optional)
It must be greater than the maximum row in the CVS file. This parameter is optional in PHP 5. If this parameter is ignored (set to 0 in PHP 5.0.4 and later versions), the length is not limited, but the execution efficiency may be affected.
Delimiter (optional)
Set the field delimiter (only one character is allowed). The default value is comma.
Enclosure (optional)
Set the field surround character (only one character is allowed). The default value is double quotation marks. This parameter is added in PHP 4.3.0.
Similar to fgets (), only the rows read by fgetcsv () are parsed, fields in CSV format are found, and an array containing these fields is returned.
If an error occurs in fgetcsv (), FALSE is returned, including when the file ends.
1 2