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