Example of Fgetcsv () function usage in PHP

Source: Internet
Author: User
This article mainly introduces the Fgetcsv () function usage in PHP, demonstrates the method of using Fgetcsv () function to manipulate CSV format file in the instance form, has certain reference value, the need friend can refer to the following

The Fgetcsv () function reads a row from the file pointer and resolves the CSV field.

Similar to Fgets (), the difference is that fgetcsv () parses a read-in row and finds a field in CSV format, and then returns an array containing those fields.

Fgetcsv () returns FALSE when an error occurs, including when the file ends.

Note: from PHP 4.3.5, the operation of Fgetcsv () is binary safe.

Grammar

Fgetcsv (File,length,separator,enclosure)
Parameters Description
File Necessary. Specifies the documents to be inspected.
Length

Optional. Specifies the maximum length of the line. Must be greater than the longest line within the CVS file.

This parameter is optional in PHP 5. is required prior to PHP 5.

If this parameter is omitted (set to 0 in a later version of PHP 5.0.4), then there is no limit to the length, but it may affect execution efficiency.

Separator Optional. Set the field delimiter (one character only), and the default value is a comma.
Enclosure

Optional. Sets the field wrapping character (only one character is allowed), and the default value is double quotation marks.

This parameter is added in PHP 4.3.0.

Note: Empty rows in a CSV file are returned as an array containing a single null field and will not be treated as an error.

Note: This function is sensitive to locale settings. Let's say LANG is set to en_US. UTF-8, a single-byte encoded file will receive a read error.

Note: You can activate the Auto_detect_line_endings runtime configuration option if you encounter a line terminator for a Macintosh file that is not recognized by PHP when reading a file.

The Fgetcsv () function instance code is as follows:

<?php $file = fopen ("Contacts.csv", "R"), Print_r (Fgetcsv ($file)); Fclose ($ file); 

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.