mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-04-28 11:13:14 +02:00
0ea7904639
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@166698 c90b9560-bf6c-de11-be94-00142212c4b1
130 lines
3.6 KiB
XML
130 lines
3.6 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.9 $ -->
|
|
<!-- EN-Revision: 1.5 Maintainer: didou Status: ready -->
|
|
<refentry id="function.strtok">
|
|
<refnamediv>
|
|
<refname>strtok</refname>
|
|
<refpurpose>Coupe une chaîne en segments</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<methodsynopsis>
|
|
<type>string</type><methodname>strtok</methodname>
|
|
<methodparam><type>string</type><parameter>str</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>token</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>strtok</function> coupe la chaîne <parameter>str</parameter>
|
|
en segments, chaque segment étant délimité par
|
|
<parameter>token</parameter>. Par exemple, si vous avez une chaîne
|
|
telle que "Voici un bon exemple", vous pouvez en extraire les
|
|
différents mots en utilisant cette fonction :
|
|
<example>
|
|
<title>Exemple avec <function>strtok</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$string = "Ceci est\tun bon\nexemple";
|
|
// Utilisez aussi les nouvelles lignes et les tabulations comme séparateur de mots
|
|
$tok = strtok($string," \n\t");
|
|
while ($tok) {
|
|
echo "Mot = $tok<br />";
|
|
$tok = strtok(" \n\t");
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Notez que seul le premier appel à <function>strtok</function>
|
|
nécessite les deux arguments. Tous les appels ultérieurs à
|
|
<function>strtok</function> ne nécessitent que la chaîne à
|
|
découper. Pour initialiser à nouveau <function>strtok</function>,
|
|
ou pour recommencer, fournissez à nouveau le paramètre
|
|
<parameter>token</parameter>. La chaîne <parameter>str</parameter>
|
|
sera découpé dès que l'un des caractères de <parameter>token</parameter>
|
|
est trouvé.
|
|
</para>
|
|
<para>
|
|
Le comportement de cette fonction avec la chaîne vide a changé depuis
|
|
&php; 4.1.0. L'ancien comportement était de retourner une chaîne vide,
|
|
tandis que le nouveau comportement, plus correct, retourne &false;
|
|
<example>
|
|
<title>Ancien comportement de <function>strtok</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$first_token = strtok('/chose', '/');
|
|
$second_token = strtok('/');
|
|
var_dump($first_token, $second_token);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
string(0) ""
|
|
string(9) "chose"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
<example>
|
|
<title>Nouveau comportement de <function>strtok</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$first_token = strtok('/chose', '/');
|
|
$second_token = strtok('/');
|
|
var_dump($first_token, $second_token);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
string(9) "chose"
|
|
bool(false)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
De plus, soyez prudents avec les séparateurs qui sont égaux à
|
|
"0". Ces valeurs s'évaluent comme &false; dans les
|
|
expression conditionnelles.
|
|
</para>
|
|
<para>
|
|
Voir aussi
|
|
<function>split</function> et
|
|
<function>explode</function>.
|
|
</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:"../../../../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
|
|
-->
|