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] = =
)