mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-26 01:42:09 +01:00
266 lines
7.0 KiB
XML
266 lines
7.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 41c8533ff5a8f93ba9fdf0732d05dd5ab79864c9 Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
<refentry xml:id="function.preg-split" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>preg_split</refname>
|
|
<refpurpose>Éclate une chaîne par expression rationnelle</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>array</type><type>false</type></type><methodname>preg_split</methodname>
|
|
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>subject</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>limit</parameter><initializer>-1</initializer></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Éclate une chaîne par expression rationnelle.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>pattern</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Le masque à chercher, sous la forme d'une &string;.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>subject</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
La chaîne d'entrée.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>limit</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si <parameter>limit</parameter> est spécifié, alors seules les
|
|
<parameter>limit</parameter> premières sous-chaînes sont retournées
|
|
avec le reste de la chaîne placé dans la dernière sous-chaîne.
|
|
Une <parameter>limit</parameter> de -1 ou 0 signifie "aucune limite".
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>flags</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<parameter>flags</parameter> peut être la combinaison des
|
|
options suivantes (combinées avec l'opérateur <literal>|</literal>):
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><constant>PREG_SPLIT_NO_EMPTY</constant></term>
|
|
<listitem>
|
|
<simpara>
|
|
Si cette option est activée, seules les sous-chaînes non vides
|
|
seront retournées par <function>preg_split</function>.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><constant>PREG_SPLIT_DELIM_CAPTURE</constant></term>
|
|
<listitem>
|
|
<simpara>
|
|
Si cette option est activée, les expressions entre parenthèses entre
|
|
les délimiteurs de masques seront aussi capturées et retournées.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><constant>PREG_SPLIT_OFFSET_CAPTURE</constant></term>
|
|
<listitem>
|
|
<para>
|
|
Si cette option est activée, pour chaque résultat, la position de celui-ci sera retournée.
|
|
Notez que cela change la valeur retournée en un tableau où chaque élément est un
|
|
tableau constitué de la chaîne trouvée à la position &zero;
|
|
et la position de la chaîne dans <parameter>subject</parameter> à
|
|
la position &one;.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retourne un tableau contenant les sous-chaînes de <parameter>subject</parameter>,
|
|
séparées par les chaînes qui vérifient <parameter>pattern</parameter>, &return.falseforfailure;.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
&pcre.pattern.warning;
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <function>preg_split</function> : Éclatement d'une chaîne de recherche</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// scinde la phrase grâce aux virgules et espacements
|
|
// ce qui inclus les " ", \r, \t, \n et \f
|
|
$keywords = preg_split("/[\s,]+/", "langage hypertexte, programmation");
|
|
print_r($keywords);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => langage
|
|
[1] => hypertexte
|
|
[2] => programmation
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Scinder une chaîne en caractères</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$str = 'string';
|
|
$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
|
|
print_r($chars);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => s
|
|
[1] => t
|
|
[2] => r
|
|
[3] => i
|
|
[4] => n
|
|
[5] => g
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Scinde une chaîne et capture les positions</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$str = 'langage hypertexte, programmation';
|
|
$chars = preg_split('/ /', $str, -1, PREG_SPLIT_OFFSET_CAPTURE);
|
|
print_r($chars);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => Array
|
|
(
|
|
[0] => langage
|
|
[1] => 0
|
|
)
|
|
|
|
[1] => Array
|
|
(
|
|
[0] => hypertexte,
|
|
[1] => 8
|
|
)
|
|
|
|
[2] => Array
|
|
(
|
|
[0] => programmation
|
|
[1] => 20
|
|
)
|
|
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<tip>
|
|
<para>
|
|
Si vous n'avez pas besoin de la puissance des expressions régulières,
|
|
vous pouvez choisir des alternatives plus rapides (quoique plus simples)
|
|
comme <function>explode</function> ou <function>str_split</function>.
|
|
</para>
|
|
</tip>
|
|
<tip>
|
|
<para>
|
|
Si la recherche d'une correspondance échoue, un tableau contenant qu'un
|
|
seul élément contenant la chaîne d'entrée sera retourné.
|
|
</para>
|
|
</tip>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><link linkend="pcre.pattern">Masques PCRE</link></member>
|
|
<member><function>preg_quote</function></member>
|
|
<member><function>implode</function></member>
|
|
<member><function>preg_match</function></member>
|
|
<member><function>preg_match_all</function></member>
|
|
<member><function>preg_replace</function></member>
|
|
<member><function>preg_last_error</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
|
|
-->
|