mirror of
https://github.com/php/doc-ja.git
synced 2026-03-25 23:52:16 +01:00
* PHP 8.4: CSV related changes and deprecations の取り込み https://github.com/php/doc-en/pull/4093 以下も合わせて取り込む reference/spl/splfileobject/setcsvcontrol.xml - [skip-revcheck] Fill xi:fallback to avoid 'variablelist incomplete' in some translations - https://github.com/php/doc-en/pull/4128 - Update setcsvcontrol.xml Fix typo - https://github.com/php/doc-en/pull/4379 reference/spl/splfileobject/fgetcsv.xml - Update fgetcsv.xml Remove the duplicate sentence - https://github.com/php/doc-en/pull/4111 * Fix GH-4175: do not say the parameters are optional の取り込み https://github.com/php/doc-en/pull/4177 * Document str_getcsv() and fgetcsv() change in 8.3.0 (closes #4197) の取り込み https://github.com/php/doc-en/pull/4198 * Fix: Add explicit $escape parameter in fputcsv for PHP 8.4 compatibility の取り込み https://github.com/php/doc-en/pull/4283 * 改行位置を原文と合わせる対応 --------- Co-authored-by: 武田 憲太郎 <takeda@youmind.jp>
224 lines
7.9 KiB
XML
224 lines
7.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: f1eb91d07d2df082384b3f83c9d2a0dc1e439d32 Maintainer: masakielastic Status: ready -->
|
|
<!-- Credits: mumumu -->
|
|
<refentry xml:id="splfileobject.fgetcsv" xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude">
|
|
<refnamediv>
|
|
<refname>SplFileObject::fgetcsv</refname>
|
|
<refpurpose>ファイルから行を取り出し CSV フィールドとして処理する</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis role="SplFileObject">
|
|
<modifier>public</modifier> <type class="union"><type>array</type><type>false</type></type><methodname>SplFileObject::fgetcsv</methodname>
|
|
<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>
|
|
</methodsynopsis>
|
|
<para>
|
|
<acronym>CSV</acronym> フォーマットのファイルから行を取り出し読み込まれたフィールドを含む配列を返します。
|
|
</para>
|
|
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('function.fgetcsv')/db:refsect1[@role='description']//db:note/.)">
|
|
<xi:fallback/>
|
|
</xi:include>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>separator</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
フィールドの区切り文字 (シングルバイト文字 1 文字のみ)。
|
|
デフォルトはカンマ(<literal>,</literal>)、 もしくは事前に
|
|
<methodname>SplFileObject::setCsvControl</methodname> を呼び出してセットされた値です。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>enclosure</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
フィールド囲み文字 (シングルバイト文字 1 文字のみ)。
|
|
デフォルトはダブルクォート(<literal>"</literal>)、もしくは事前に
|
|
<methodname>SplFileObject::setCsvControl</methodname> を呼び出してセットされた値です。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>escape</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
エスケープ文字 (シングルバイト文字 最大で1文字)。
|
|
デフォルトはバックスラッシュ(<literal>\</literal>)、 もしくは事前に
|
|
<methodname>SplFileObject::setCsvControl</methodname> を呼び出してセットされた値です。
|
|
空文字列(<literal>""</literal>)の場合、(RFC 4180 に準拠していない) 独自仕様のエスケープ機構が無効になります。
|
|
</para>
|
|
<note>
|
|
<simpara>
|
|
<parameter>enclosure</parameter> の文字は、フィールド内で2回出力される
|
|
ことでエスケープされます。しかし、
|
|
<parameter>escape</parameter> 文字はその代替として使えます。
|
|
デフォルトのパラメータの値
|
|
<literal>""</literal> と <literal>\"</literal> は同じ意味を持ちます。
|
|
<parameter>enclosure</parameter> の文字を
|
|
<parameter>escape</parameter> 文字でエスケープすることには、
|
|
特別な意味はありません。それ自身をエスケープする意味ですらありません。
|
|
</simpara>
|
|
</note>
|
|
<warning>
|
|
<simpara>
|
|
PHP 8.4.0 以降では、<parameter>escape</parameter>
|
|
のデフォルト値に依存することは非推奨となりました。
|
|
位置指定の引数か、<link linkend="functions.named-arguments">名前付き引数</link>を使用するか、
|
|
あるいは <methodname>SplFileObject::setCsvControl</methodname>
|
|
を呼び出して、明示的に指定する必要があります。
|
|
</simpara>
|
|
</warning>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
&warning.csv.escape-parameter;
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
読み込まれたフィールドを含む数値添字配列もしくはエラーのときは &false; を返します。
|
|
</para>
|
|
<note>
|
|
<para>
|
|
CSV ファイルの空白行は <constant>SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE</constant> を使わない限り単独の &null; フィールドで構成される配列として返され、この場合空白行は読み飛ばされます。
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('function.fgetcsv')/db:refsect1[@role='errors']/.)">
|
|
<xi:fallback/>
|
|
</xi:include>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('function.fgetcsv')/db:refsect1[@role='changelog']//db:row[db:entry[text()='8.4.0']]/.)">
|
|
<xi:fallback/>
|
|
</xi:include>
|
|
<row>
|
|
<entry>7.4.0</entry>
|
|
<entry>
|
|
<parameter>escape</parameter> パラメータは空文字列を受け入れるようになりました。
|
|
この場合、(RFC 4180 に準拠していない) 独自仕様のエスケープ機構が無効になります。
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><methodname>SplFileObject::fgetcsv</methodname> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$file = new SplFileObject("data.csv");
|
|
while (!$file->eof()) {
|
|
var_dump($file->fgetcsv());
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><constant>SplFileObject::READ_CSV</constant> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$file = new SplFileObject("animals.csv");
|
|
$file->setFlags(SplFileObject::READ_CSV);
|
|
foreach ($file as $row) {
|
|
list($animal, $class, $legs) = $row;
|
|
printf("A %s is a %s with %d legs\n", $animal, $class, $legs);
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>animals.csv の内容</para>
|
|
<programlisting role="txt">
|
|
<![CDATA[
|
|
crocodile,reptile,4
|
|
dolphin,mammal,0
|
|
duck,bird,2
|
|
koala,mammal,4
|
|
salmon,fish,0
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
A crocodile is a reptile with 4 legs
|
|
A dolphin is a mammal with 0 legs
|
|
A duck is a bird with 2 legs
|
|
A koala is a mammal with 4 legs
|
|
A salmon is a fish with 0 legs
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<simplelist>
|
|
<member><methodname>SplFileObject::fputcsv</methodname></member>
|
|
<member><methodname>SplFileObject::setCsvControl</methodname></member>
|
|
<member><methodname>SplFileObject::getCsvControl</methodname></member>
|
|
<member><methodname>SplFileObject::setFlags</methodname></member>
|
|
<member><constant>SplFileObject::READ_CSV</constant></member>
|
|
<member><methodname>SplFileObject::current</methodname></member>
|
|
<member><function>fputcsv</function></member>
|
|
<member><function>fgetcsv</function></member>
|
|
<member><function>str_getcsv</function></member>
|
|
</simplelist>
|
|
</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
|
|
-->
|