Rewrote to hopefully make more sense. See also explode, file, and pack.

Moved "enclosure added in PHP 4.3.0" to a note.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@100094 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2002-10-18 01:48:11 +00:00
parent beb88e3da0
commit 45f6127d4d

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<!-- $Revision: 1.5 $ -->
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
<refentry id="function.fgetcsv">
<refnamediv>
@ -19,20 +19,24 @@
Similar to <function>fgets</function> except that
<function>fgetcsv</function> parses the line it reads for fields
in <acronym>CSV</acronym> format and returns an array containing
the fields read. The field delimiter is a comma, unless you
specify another delimiter with the optional third parameter. The
enclosure character is double quote, unless it is
specified. <parameter>Delimiter</parameter> and
<parameter>enclosure</parameter> cannot be null and only first
character is used when they are specified.
the fields read. The optional third <parameter>delimiter</parameter>
parameter defaults as a comma. The optional <parameter>enclosure</parameter>
cannot be <type>null</type>, and is limited to one character. If
<parameter>enclosure</parameter> is more than one character, only the
first character is used.
</simpara>
<note>
<simpara>
The <parameter>enclosure</parameter> parameter was added in PHP 4.3.0.
</simpara>
</note>
<simpara>
<parameter>Fp</parameter> must be a valid file pointer to a file
The <parameter>fp</parameter> parameter must be a valid file pointer to a file
successfully opened by <function>fopen</function>,
<function>popen</function>, or <function>fsockopen</function>
<function>popen</function>, or <function>fsockopen</function>.
</simpara>
<simpara>
<parameter>Length</parameter> must be greater than the longest
The <parameter>length</parameter> parameter must be greater than the longest
line to be found in the CSV file (allowing for trailing line-end characters).
</simpara>
<simpara>
@ -42,34 +46,36 @@
<note>
<simpara>
A blank line in a CSV file will be returned as an array
comprising a single &null; field, and will not be treated as an
error.
</simpara>
<simpara>
<parameter>enclosure</parameter> is added from PHP 4.3.0.
comprising a single <type>null</type> field, and will not be treated
as an error.
</simpara>
</note>
<example>
<title>
<function>fgetcsv</function> example - Read and print entire
contents of a CSV file
</title>
<programlisting role="php">
<para>
<example>
<title>Read and print the entire contents of a CSV file</title>
<programlisting role="php">
<![CDATA[
<?php
$row = 1;
$fp = fopen ("test.csv","r");
while ($data = fgetcsv ($fp, 1000, ",")) {
$num = count ($data);
print "<p> $num fields in line $row: <br>";
print "<p> $num fields in line $row: <br>\n";
$row++;
for ($c=0; $c < $num; $c++) {
print $data[$c] . "<br>";
print $data[$c] . "<br>\n";
}
}
fclose ($fp);
?>
]]>
</programlisting>
</example>
</programlisting>
</example>
</para>
<para>
See also <function>explode</function>, <function>file</function>,
and <function>pack</function>
</para>
</refsect1>
</refentry>