mirror of
https://github.com/php/doc-es.git
synced 2026-03-25 16:02:13 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@333815 c90b9560-bf6c-de11-be94-00142212c4b1
161 lines
4.8 KiB
XML
161 lines
4.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 8b6d169424ff189bb563ef4c3f35f8adff3f42c5 Maintainer: andresdzphp Status: ready -->
|
|
<!-- Reviewed: yes Maintainer: seros -->
|
|
|
|
<refentry xml:id="splfileobject.fgetcsv" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>SplFileObject::fgetcsv</refname>
|
|
<refpurpose>Obtiene una línea de un fichero y la analiza como campos CSV</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<modifier>public</modifier> <type>array</type><methodname>SplFileObject::fgetcsv</methodname>
|
|
<methodparam choice="opt"><type>string</type><parameter>delimiter</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>
|
|
Obtiene una línea del fichero la cual está en formato <acronym>CSV</acronym> y devuelve un array que contiene los campos leídos.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>delimiter</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El delimitador de campos (sólo un carácter). Por omisión, es una coma o el valor establecido por <methodname>SplFileObject::setCsvControl</methodname>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>enclosure</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El carácter circundante de cada campo (sólo un carácter). Por omisión, son comillas dobles o el valor establecido por <methodname>SplFileObject::setCsvControl</methodname>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>escape</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El carácter de escape (sólo un carácter). Por omisión, es una barra invertida (<literal>\</literal>) o el valor establecido por <methodname>SplFileObject::setCsvControl</methodname>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Devuelve un array indexado que contiene los campos leídos, o &false; en caso de error.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Una línea en blanco en un fichero CSV será devuelta como un array constituido
|
|
por un campo &null; a menos que se establezca <constant>SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE</constant>,
|
|
en cuyo caso se omiten las líneas vacías.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <methodname>SplFileObject::fgetcsv</methodname></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$fichero = new SplFileObject("datos.csv");
|
|
while (!$fichero->eof()) {
|
|
var_dump($fichero->fgetcsv());
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <constant>SplFileObject::READ_CSV</constant></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$fichero = new SplFileObject("animales.csv");
|
|
$fichero->setFlags(SplFileObject::READ_CSV);
|
|
foreach ($fichero as $fila) {
|
|
list($animal, $clase, $patas) = $fila;
|
|
printf("Un %s es un %s con %d patas\n", $animal, $clase, $patas);
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>Contenido de animales.csv</para>
|
|
<programlisting role="txt">
|
|
<![CDATA[
|
|
cocodrilo,reptil,4
|
|
delfín,mamífero,0
|
|
pato,ave,2
|
|
koala,mamífero,4
|
|
salmón,pez,0
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Un cocodrilo es un reptil con 4 patas
|
|
Un delfín es un mamífero con 0 patas
|
|
Un pato es un ave con 2 patas
|
|
un koala es un mamífero con 4 patas
|
|
Un salmón es un pez con 0 patas
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><methodname>SplFileObject::setCsvControl</methodname></member>
|
|
<member><methodname>SplFileObject::setFlags</methodname></member>
|
|
<member><link linkend="splfileobject.constants.read-csv">SplFileObject::READ_CSV</link></member>
|
|
<member><methodname>SplFileObject::current</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
|
|
-->
|