? Phpfunctionget_csv_contents ($ file_target) {$ handlenbs...
$num fields in line $row:
"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c]. "
";; /*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)
This parameter must be greater than the longest line in the CVS file. in PHP 5, this parameter is optional. If this parameter is ignored (set to 0 in PHP 5.0.4 and later versions, there is no limit on the length, but it may affect the execution efficiency.
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.
Note: empty rows in the CSV file will be returned as an array containing a single null field and will not be treated as an error.
Example 1: read and display the entire content of the CSV file. the code is as follows:
$row = 1; $handle = fopen("test.csv","r"); while ($data = fgetcsv($handle, 1000, ",")) { $num = count($data);echo " $num fields in line $row:
"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "
"; } } fclose($handle);
Permanent link:
Reprint at will! Include the article address.