About the Fgetcsv function

Source: Internet
Author: User
Fgetcsv (Resource fp,int length [, String delimiter, String enclosure, escape]])

Please explain the red part. Write an example.

What does Green do?


Reply to discussion (solution)

Array Fgetcsv (Resource $handle [, int $length = 0 [, String $delimiter = ', ' [, String $enclosure = ' "' [, String $escap e = ' \ \ ']]])
Similar to Fgets (), only fgetcsv () resolves the read-in rows and finds fields in CSV format and returns an array containing those fields.
Parameter ¶
Handle
A valid file pointer produced by fopen (), Popen (), or fsockopen ().
Length
Must be greater than the longest line within the CVS file. This parameter is optional in 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.
Delimiter
Sets the field delimiter (only one character is allowed).
Enclosure
Set the field wrapping character (only one characters allowed).
Escape
Sets the escape character (only one character is allowed), and the default is a backslash.

PHP fgetcsv () function

Array Fgetcsv (Resource $handle [, int $length = 0 [, String $delimiter = ', ' [, String $enclosure = ' "' [, String $escap e = ' \ \ ']]])
Similar to Fgets (), only fgetcsv () resolves the read-in rows and finds fields in CSV format and returns an array containing those fields.
Parameter ¶
Handle
A valid file pointer produced by fopen (), Popen (), or fsockopen ().
Length
Must be greater than the longest line within the CVS file. This parameter is optional in 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.
Delimiter
Sets the field delimiter (only one character is allowed).
Enclosure
Set the field wrapping character (only one characters allowed).
Escape
Sets the escape character (only one character is allowed), and the default is a backslash.


I want to know how to use the Enclosure,escape parameter. Give an example.

$s =<<< TXTAAA,BBB,CCC "AAA", "BBB", "CCC" ' AAA ' | ' BBB ' | ' CCC ' txt;file_put_contents (' csv_test.txt ', $s); $fp = fopen (' csv_test.txt ', ' R ');p Rint_r (Fgetcsv ($fp));p Rint_r ( Fgetcsv ($fp));p Rint_r (Fgetcsv ($fp, "|", "'"));
Array
(
[0] = AAA
[1] = BBB
[2] = = CCC
)
Array
(
[0] = AAA
[1] = BBB
[2] = = CCC
)
Array
(
[0] = =
[1] = AAA
[2] = |
[3] = BBB
[4] = |
[5] = = CCC
[6] = =
)
  • 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.