PHP fgetcsv function _php Tutorial

Source: Internet
Author: User
PHP fgetcsv functions

Fgetcsv
(PHP 4, PHP 5)

Fgetcsv-Gets the line from the file pointer and resolves to the CSV field

Describe
Array Fgetcsv (resource $ handling [digest $ length [, String $ delimiter [, String $ enclosure [, String $ escape]]])
Similar to Fgets (), but Fgetcsv () parses the line to read the field in CSV format and returns an array containing the field reads.

Parameters

Handle
A valid file pointer to the file successfully opened the fopen () function, Popen (), or fsockopen ().

Length
Must be larger than the longest line (in characters) that can be found in the CSV file (trailing lines are allowed at the end of the character). It becomes optional in PHP 5. Omitting this parameter (or setting to 0 in PHP 5.0.4 and later) is limited to the length of the maximum line, which is slightly slower.

Delimiter
The field delimiter for the set (only one character). The default value is a comma.

Text
Sets the field characters (one character only). The default is double quotation marks.

Escape
Sets the escape character (only one character). The default value is a backslash ()


return value
Returns an array containing the indexed field reads.

Note: A blank line of CSV files will return an array consisting of a single empty space and will not be considered an error.


Note: If PHP does not correctly recognize the end of the line, whether it is reading a file or creating a Macintosh computer, making the Auto_detect_line_endings runtime configuration option may help resolve this issue.

Fgetcsv () returns false error, including end of file.

Modify

Release Notes
5.3.0 Jailbreak parameter increased
4.3.5 Fgetcsv () is now a binary security
4.3.0 Attachment parameter Increase


Instance

For example # 1 read and print the full contents of the CSV file

$row = 1;
$handle = fopen ("Test.csv", "R");
while ($data = Fgetcsv ($handle, +, ","))!== FALSE) {
$num = count ($data);
echo "

$num Fields $row:

n ";
$row + +;
for ($c =0; $c < $num; $c + +) {
echo $data [$c]. "
n ";
}
}
Fclose ($handle);
?>


http://www.bkjia.com/PHPjc/445476.html www.bkjia.com true http://www.bkjia.com/PHPjc/445476.html techarticle php fgetcsv function fgetcsv (PHP 4, PHP 5) fgetcsv-Gets the line from the file pointer and resolves to the CSV domain description array fgetcsv (resource $ processing [abstract $ length [, string $ bound ...)

  • 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.