document SplFileObject::fputcsv() (doc #60878)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@325467 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Peter Cowburn 2012-04-26 21:21:29 +00:00
parent 649f89731c
commit 376417834e
2 changed files with 72 additions and 12 deletions

View file

@ -4,23 +4,20 @@
<refentry xml:id="splfileobject.fputcsv" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>SplFileObject::fputcsv</refname>
<refpurpose>Output a field array as a CSV line</refpurpose>
<refpurpose>Write a field array as a CSV line</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>int</type><methodname>SplFileObject::fputcsv</methodname>
<methodparam><type>string</type><parameter>fields</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>delimiter</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>enclosure</parameter></methodparam>
<methodparam><type>array</type><parameter>fields</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>delimiter</parameter><initializer>','</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>enclosure</parameter><initializer>'"'</initializer></methodparam>
</methodsynopsis>
<para>
Writes the <parameter>fields</parameter> array to the file as a CSV line.
</para>
&warn.undocumented.func;
</refsect1>
<refsect1 role="parameters">
@ -30,7 +27,7 @@
<term><parameter>fields</parameter></term>
<listitem>
<para>
An array of values.
</para>
</listitem>
</varlistentry>
@ -38,7 +35,8 @@
<term><parameter>delimiter</parameter></term>
<listitem>
<para>
The optional <parameter>delimiter</parameter> parameter sets the field
delimiter (one character only).
</para>
</listitem>
</varlistentry>
@ -46,7 +44,8 @@
<term><parameter>enclosure</parameter></term>
<listitem>
<para>
The optional <parameter>enclosure</parameter> parameter sets the field
enclosure (one character only).
</para>
</listitem>
</varlistentry>
@ -56,10 +55,70 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the length of the written string&return.falseforfailure;.
</para>
<para>
Returns &false;, and does not write the CSV line to the file, if the
<parameter>delimiter</parameter> or <parameter>enclosure</parameter>
parameter is not a single character.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
An <constant>E_WARNING</constant> level error is issued if the
<parameter>delimiter</parameter> or <parameter>enclosure</parameter>
parameter is not a single character.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example xml:id="splfileobject.fputcsv.examples.basic">
<title><methodname>SplFileObject::fputcsv</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php
$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);
$file = new SplFileObject('file.csv', 'w');
foreach ($list as $fields) {
$file->fputcsv($fields);
}
?>
]]>
</programlisting>
<para>The above example will write the following to <literal>file.csv</literal>:</para>
<screen>
<![CDATA[
aaa,bbb,ccc,dddd
123,456,789
"""aaa""","""bbb"""
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>fputcsv</function></member>
<member><methodname>SplFileObject::fgetcsv</methodname></member>
</simplelist>
</para>
</refsect1>
</refentry>

View file

@ -704,6 +704,7 @@
<function name='splfileobject::fgetss' from='PHP 5 &gt;= 5.1.0'/>
<function name='splfileobject::flock' from='PHP 5 &gt;= 5.1.0'/>
<function name='splfileobject::fpassthru' from='PHP 5 &gt;= 5.1.0'/>
<function name='splfileobject::fputcsv' from='PHP 5 &gt;= 5.4.0'/>
<function name='splfileobject::fscanf' from='PHP 5 &gt;= 5.1.0'/>
<function name='splfileobject::fseek' from='PHP 5 &gt;= 5.1.0'/>
<function name='splfileobject::fstat' from='PHP 5 &gt;= 5.1.0'/>