File system function Library: Fgetcsv

Source: Internet
Author: User
Keywords fgetcsv php Chinese function manual file system function library
Tags aliyun array csv data file file system function library function function library

Fgetcsv

(PHP3 >= 3.0.8, PHP4)

Fgetcsv---&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp; Get rows from file metrics and parse CSV fields

Syntax: array fgetcsv (int fp, int length [, String delimiter])

Description:

Similar to Fgets (), where the function is to parse the CSV field data of the rows being read, and to return the data to the array, the definition symbol for the field is a comma, unless you specify another definition symbol in the third argument.

The file index FP must be valid and is an indicator of the successful opening of fopen (), Popen (), Fsockopen ().

Length must be greater than the longest line in the CSV file (allow the end of the line to be exceeded).

Fgetcsv () error or return false at the end of the file.

A single null field in the array returned in the CSV file if there is a blank line is not considered an error.

Example:

<?php

$row = 1;

$fp = fopen ("Test.csv", "R");

while ($data = Fgetcsv ($fp, 1000, ",")) {

$num = count ($data);

Print "<p> $num fields in $row: <br>";

$row + +;

For ($c =0 $c < $num; $c + +) {

Print $data [$c]. "<br>";

}

}

Fclose ($FP);

?>

Related Article

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.