<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.pcre.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.preg-split.php',
    1 => 'preg_split',
    2 => '&Eacute;clate une cha&icirc;ne par expression rationnelle',
  ),
  'up' => 
  array (
    0 => 'ref.pcre.php',
    1 => 'Fonctions PCRE',
  ),
  'prev' => 
  array (
    0 => 'function.preg-replace-callback-array.php',
    1 => 'preg_replace_callback_array',
  ),
  'next' => 
  array (
    0 => 'book.ssdeep.php',
    1 => 'ssdeep',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/pcre/functions/preg-split.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.preg-split" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">preg_split</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">preg_split</span> &mdash; <span class="dc-title">Éclate une chaîne par expression rationnelle</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.preg-split-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>preg_split</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$pattern</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$subject</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$limit</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span><br>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Éclate une chaîne par expression rationnelle.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.preg-split-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">pattern</code></dt>
     <dd>
      <p class="para">
       Le masque à chercher, sous la forme d&#039;une <a href="language.types.string.php" class="link">chaîne de caractères</a>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">subject</code></dt>
     <dd>
      <p class="para">
       La chaîne d&#039;entrée.
      </p>
     </dd>
    
    
     <dt><code class="parameter">limit</code></dt>
     <dd>
      <p class="para">
       Si <code class="parameter">limit</code> est spécifié, alors seules les
       <code class="parameter">limit</code> premières sous-chaînes sont retournées
       avec le reste de la chaîne placé dans la dernière sous-chaîne.
       Une <code class="parameter">limit</code> de -1 ou 0 signifie &quot;aucune limite&quot;.
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">flags</code> peut être la combinaison des
       options suivantes (combinées avec l&#039;opérateur <code class="literal">|</code>):
       <dl>
        
         <dt><strong><code><a href="pcre.constants.php#constant.preg-split-no-empty">PREG_SPLIT_NO_EMPTY</a></code></strong></dt>
         <dd>
          <span class="simpara">
          Si cette option est activée, seules les sous-chaînes non vides
          seront retournées par <span class="function"><strong>preg_split()</strong></span>.
          </span>
         </dd>
        
        
         <dt><strong><code><a href="pcre.constants.php#constant.preg-split-delim-capture">PREG_SPLIT_DELIM_CAPTURE</a></code></strong></dt>
         <dd>
          <span class="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.
          </span>
         </dd>
        
        
         <dt><strong><code><a href="pcre.constants.php#constant.preg-split-offset-capture">PREG_SPLIT_OFFSET_CAPTURE</a></code></strong></dt>
         <dd>
          <p class="para">
           Si cette option est activée, pour chaque résultat, la position de celui-ci sera retournée.
           À noter 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 <code class="literal">0</code>
           et la position de la chaîne dans <code class="parameter">subject</code> à
           la position <code class="literal">1</code>.
          </p>
         </dd>
        
       </dl>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.preg-split-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne un tableau contenant les sous-chaînes de <code class="parameter">subject</code>,
   séparées par les chaînes qui vérifient <code class="parameter">pattern</code>,  ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si une erreur survient.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.preg-split-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="para">
Si le masque regex passé ne compile pas à une regex valide, une <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> est émise.
</p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.preg-split-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>preg_split()</strong></span> : Éclatement d&#039;une chaîne de recherche</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// scinde la phrase grâce aux virgules et espacements<br />// ce qui inclus les " ", \r, \t, \n et \f<br /></span><span style="color: #0000BB">$keywords </span><span style="color: #007700">= </span><span style="color: #0000BB">preg_split</span><span style="color: #007700">(</span><span style="color: #DD0000">"/[\s,]+/"</span><span style="color: #007700">, </span><span style="color: #DD0000">"langage hypertexte, programmation"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$keywords</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [0] =&gt; langage
    [1] =&gt; hypertexte
    [2] =&gt; programmation
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Scinder une chaîne en caractères</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">'string'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$chars </span><span style="color: #007700">= </span><span style="color: #0000BB">preg_split</span><span style="color: #007700">(</span><span style="color: #DD0000">'//'</span><span style="color: #007700">, </span><span style="color: #0000BB">$str</span><span style="color: #007700">, -</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">PREG_SPLIT_NO_EMPTY</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$chars</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [0] =&gt; s
    [1] =&gt; t
    [2] =&gt; r
    [3] =&gt; i
    [4] =&gt; n
    [5] =&gt; g
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Exemple #3 Scinde une chaîne et capture les positions</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">'langage hypertexte, programmation'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$chars </span><span style="color: #007700">= </span><span style="color: #0000BB">preg_split</span><span style="color: #007700">(</span><span style="color: #DD0000">'/ /'</span><span style="color: #007700">, </span><span style="color: #0000BB">$str</span><span style="color: #007700">, -</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">PREG_SPLIT_OFFSET_CAPTURE</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$chars</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [0] =&gt; Array
        (
            [0] =&gt; langage
            [1] =&gt; 0
        )

    [1] =&gt; Array
        (
            [0] =&gt; hypertexte,
            [1] =&gt; 8
        )

    [2] =&gt; Array
        (
            [0] =&gt; programmation
            [1] =&gt; 20
        )

)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.preg-split-notes">
  <h3 class="title">Notes</h3>
  <div class="tip"><strong class="tip">Astuce</strong>
   <p class="para">
    S&#039;il n&#039;est pas nécessaire de la puissance des expressions régulières,
    il est possible de choisir des alternatives plus rapides (quoique plus simples)
    comme <span class="function"><a href="function.explode.php" class="function">explode()</a></span> ou <span class="function"><a href="function.str-split.php" class="function">str_split()</a></span>.
   </p>
  </div>
  <div class="tip"><strong class="tip">Astuce</strong>
   <p class="para">
    Si la recherche d&#039;une correspondance échoue, un tableau contenant qu&#039;un
    seul élément contenant la chaîne d&#039;entrée sera retourné.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.preg-split-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><a href="pcre.pattern.php" class="link">Masques PCRE</a></li>
    <li><span class="function"><a href="function.preg-quote.php" class="function" rel="rdfs-seeAlso">preg_quote()</a> - Protection des caract&egrave;res sp&eacute;ciaux des expressions r&eacute;guli&egrave;res</span></li>
    <li><span class="function"><a href="function.explode.php" class="function" rel="rdfs-seeAlso">explode()</a> - Scinde une cha&icirc;ne de caract&egrave;res en segments</span></li>
    <li><span class="function"><a href="function.preg-match.php" class="function" rel="rdfs-seeAlso">preg_match()</a> - Effectue une recherche de correspondance avec une expression rationnelle standard</span></li>
    <li><span class="function"><a href="function.preg-match-all.php" class="function" rel="rdfs-seeAlso">preg_match_all()</a> - Expression rationnelle globale</span></li>
    <li><span class="function"><a href="function.preg-replace.php" class="function" rel="rdfs-seeAlso">preg_replace()</a> - Rechercher et remplacer par expression rationnelle standard</span></li>
    <li><span class="function"><a href="function.preg-last-error.php" class="function" rel="rdfs-seeAlso">preg_last_error()</a> - Retourne le code erreur de la derni&egrave;re expression PCRE ex&eacute;cut&eacute;e</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>