Php fgetcsv reads csv file code (1/2)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.