1
0
mirror of https://github.com/php/doc-es.git synced 2026-03-26 16:32:13 +01:00
Files
archived-doc-es/reference/strings/functions/strtok.xml
Juan Pablo Berdejo 6a87ef2263 New translated file
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@307595 c90b9560-bf6c-de11-be94-00142212c4b1
2011-01-19 19:45:26 +00:00

179 lines
4.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: af4410a7e15898c3dbe83d6ea38246745ed9c6fb Maintainer: jpberdejo Status: ready -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.strtok" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>strtok</refname>
<refpurpose>Tokeniza string</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>strtok</methodname>
<methodparam><type>string</type><parameter>str</parameter></methodparam>
<methodparam><type>string</type><parameter>token</parameter></methodparam>
</methodsynopsis>
<methodsynopsis>
<type>string</type><methodname>strtok</methodname>
<methodparam><type>string</type><parameter>token</parameter></methodparam>
</methodsynopsis>
<para>
<function>strtok</function> divide un string (<parameter>str</parameter>)
en strings más pequeños (tokens), con cada token delimitado por cualquier
caracter de <parameter>token</parameter>.
Es decir, si se tiene un string como "Este es un string de ejemplo", se
puede tokenizar en sus palabras individuales utilizando el
caracter de espacio como el token.
</para>
<para>
Nótese que sólo la primera llamada a strtok utiliza el argumento string.
Cada llamada subsecuente a strtok sólo necesita el token a utilizar, ya
que realiza un seguimiento del lugar en que se encuentra en el string actual. Para
volver a empezar, o para dividir una cadena nueva, simplemente se llama a strtok de nuevo
con el argumento string para inicializarlo. Tener en cuenta que se pueden poner
tokens múltiples como parámetro. El string será
tokenizado cuando cualquiera de los caracteres en el argumento sea
encontrado.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>str</parameter></term>
<listitem>
<para>
El <type>string</type> a ser dividido en strings más pequeños (tokens).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>token</parameter></term>
<listitem>
<para>
El delimitador usado cuando se divide <parameter>str</parameter>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Un token de <type>string</type>.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Ejemplo de <function>strtok</function></title>
<programlisting role="php">
<![CDATA[
<?php
$string = "This is\tan example\nstring";
/* Utiliza tabulador y nueva línea como caracteres de tokenización, así */
$tok = strtok($string, " \n\t");
while ($tok !== false) {
echo "Word=$tok<br />";
$tok = strtok(" \n\t");
}
?>
]]>
</programlisting>
</example>
</para>
<para>
El comportamiento cuando se encuentra una parte vacía, cambió con PHP 4.1.0. El comportamiento
anterior devolvía una cadena vacía, mientras que el comportamiento nuevo y correcto
simplemente se salta esa parte del string:
</para>
<para>
<example>
<title>Comportamiento anterior de <function>strtok</function></title>
<programlisting role="php">
<![CDATA[
<?php
$first_token = strtok('/something', '/');
$second_token = strtok('/');
var_dump($first_token, $second_token);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
string(0) ""
string(9) "something"
]]>
</screen>
</example>
<example>
<title>Comportamiento nuevo de <function>strtok</function></title>
<programlisting role="php">
<![CDATA[
<?php
$first_token = strtok('/something', '/');
$second_token = strtok('/');
var_dump($first_token, $second_token);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
string(9) "something"
bool(false)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&return.falseproblem;
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>split</function></member>
<member><function>explode</function></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
-->