1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-26 00:32:15 +01:00
Files
archived-doc-ru/reference/spl/splfileobject/fputcsv.xml

203 lines
6.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: d51166ca16fda8e766849505b84f9306ef443f71 Maintainer: rjhdby Status: ready -->
<!-- Reviewed: no -->
<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>Записывает массив полей как CSV-строки</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="SplFileObject">
<modifier>public</modifier> <type class="union"><type>int</type><type>false</type></type><methodname>SplFileObject::fputcsv</methodname>
<methodparam><type>array</type><parameter>fields</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>separator</parameter><initializer>","</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>enclosure</parameter><initializer>"\""</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>escape</parameter><initializer>"\\"</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>eol</parameter><initializer>"\n"</initializer></methodparam>
</methodsynopsis>
<para>
Метод записывает массив <parameter>fields</parameter> в файл как строку CSV-файла.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>fields</parameter></term>
<listitem>
<para>
Массив значений.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>separator</parameter></term>
<listitem>
<para>
Необязательный параметр <parameter>separator</parameter> устанавливает
разделитель полей (только один однобайтовый символ).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>enclosure</parameter></term>
<listitem>
<para>
Необязательный параметр <parameter>enclosure</parameter> устанавливает
ограничитель полей (только один однобайтовый символ).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>escape</parameter></term>
<listitem>
<para>
Необязательный параметр <parameter>escape</parameter> устанавливает символ
экранирования (не более одного однобайтового символа).
Пустая строка (<literal>""</literal>) отключает собственный механизм экранирования.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>eol</parameter></term>
<listitem>
<para>
Необязательный параметр <parameter>eol</parameter>
устанавливает пользовательскую последовательность конца строки.
</para>
</listitem>
</varlistentry>
</variablelist>
<note>
<para>
Метод заэкранирует символ ограничителя полей <parameter>enclosure</parameter> путём удвоения,
если поле содержит символ ограничителя, если только прямо перед символом ограничителя не стоит
символ экранирования <parameter>escape</parameter>.
</para>
</note>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Метод возвращает длину строки, которую записал,&return.falseforfailure;.
</para>
<para>
Метод возвращает &false; и не записывает CSV-строку в файл, если параметры
<parameter>separator</parameter> или <parameter>enclosure</parameter>
содержат больше одного символа.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Метод выдаёт ошибку уровня <constant>E_WARNING</constant>, если параметр
<parameter>separator</parameter> или <parameter>enclosure</parameter>
не односимвольный.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.1.0</entry>
<entry>
Добавили необязательный параметр <parameter>eol</parameter>.
</entry>
</row>
<row>
<entry>7.4.0</entry>
<entry>
Параметр <parameter>escape</parameter> теперь принимает пустую строку
для отключения механизма экранирования.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example xml:id="splfileobject.fputcsv.examples.basic">
<title>Пример использования метода <methodname>SplFileObject::fputcsv</methodname></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>Приведённый пример записывает следующие строки в файл <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>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->