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 "$num fields in line $ row:
n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c]. "< br>n";;
/*echo getUTFString($data[$c])*/
array fgetcsv ( int handle [, int length [, string delimiter [, string enclosure]]] )
handle
one by fopen( ), popen() or fsockopen().
length (optional)
must be greater than the longest line in the CVS file. This parameter is optional in PHP 5. If this parameter is omitted (set to 0 in PHP 5.0.4 and later versions), there is no limit to the length, but execution efficiency may be affected.
delimiter (optional)
Set the field delimiter (only one character allowed), the default value is comma.
enclosure (optional)
Set the field surround character (only one character allowed), the default value is double quotes. This parameter was added in PHP 4.3.0.
Similar to fgets(), except that fgetcsv() parses the read line and finds the fields in CSV format and returns an array containing those fields.
fgetcsv() returns FALSE on error, including when the end of file is encountered.
www.bkjia.com
true