<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.explode.php',
    1 => 'explode',
    2 => 'Scinde une cha&icirc;ne de caract&egrave;res en segments',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'Fonctions sur les cha&icirc;nes de caract&egrave;res',
  ),
  'prev' => 
  array (
    0 => 'function.echo.php',
    1 => 'echo',
  ),
  'next' => 
  array (
    0 => 'function.fprintf.php',
    1 => 'fprintf',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/strings/functions/explode.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.explode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">explode</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">explode</span> &mdash; <span class="dc-title">Scinde une chaîne de caractères en segments</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.explode-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>explode</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$separator</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>, <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"> = <strong><code><a href="reserved.constants.php#constant.php-int-max">PHP_INT_MAX</a></code></strong></span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>explode()</strong></span> retourne un tableau de chaînes de caractères, 
   chacune d&#039;elle étant une sous-chaîne
   du paramètre <code class="parameter">string</code> extraite en utilisant le séparateur
   <code class="parameter">separator</code>.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.explode-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">separator</code></dt>
     <dd>
      <p class="para">
       Le séparateur.
      </p>
     </dd>
    
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       La chaîne initiale.
      </p>
     </dd>
    
    
     <dt><code class="parameter">limit</code></dt>
     <dd>
      <p class="para">
       Si <code class="parameter">limit</code> est défini et positif, 
       le tableau retourné contient, au maximum, 
       <code class="parameter">limit</code> éléments, et le dernier
       élément contiendra le reste de la chaîne.
      </p>
      <p class="para">
       Si le paramètre <code class="parameter">limit</code> est négatif,
       tous les éléments, excepté les -<code class="parameter">limit</code>
       derniers éléments sont retournés.
      </p>
      <p class="para">
       Si <code class="parameter">limit</code> vaut zéro, il est traité
       comme valant 1.
      </p>
     </dd>
    
   </dl>
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Antérieur à PHP 8.0, <span class="function"><a href="function.implode.php" class="function">implode()</a></span> acceptait ses paramètres
    dans n&#039;importe quel ordre. <span class="function"><strong>explode()</strong></span> n&#039;a jamais supporté ceci :
    il faut s&#039;assurer que le paramètre <code class="parameter">separator</code>
    soit placé avant le paramètre <code class="parameter">string</code>.
   </p>
  </p></blockquote>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.explode-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne un <a href="language.types.array.php" class="link">tableau</a> de chaînes de caractères créées en scindant
   la chaîne du paramètre <code class="parameter">string</code> en plusieurs
   morceaux suivant le paramètre <code class="parameter">separator</code>.
  </p>
  <p class="para">
   Si <code class="parameter">separator</code> est une chaîne vide (&quot;&quot;),
   <span class="function"><strong>explode()</strong></span> lancera une <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>. Si
   <code class="parameter">separator</code> contient une valeur qui n&#039;est pas contenue
   dans <code class="parameter">string</code> ainsi qu&#039;une valeur négative pour le paramètre
   <code class="parameter">limit</code>, alors <span class="function"><strong>explode()</strong></span>
   retournera un <a href="language.types.array.php" class="link">tableau</a> vide, sinon, un <a href="language.types.array.php" class="link">tableau</a> contenant la chaîne
   <code class="parameter">string</code> entière.
   Si les valeurs de <code class="parameter">separator</code> apparaissent au début
   ou à la fin de <code class="parameter">string</code>, ces valeurs seront ajoutées
   comme une valeur d&#039;un <span class="type"><a href="language.types.array.php" class="type array">array</a></span> vide soit en la première ou
   dernière position du <span class="type"><a href="language.types.array.php" class="type array">array</a></span> retourné respectivement.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.explode-changelog">
  <h3 class="title">Historique</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <span class="function"><strong>explode()</strong></span> lancera désormais une <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>
       quand une chaîne vide (<code class="literal">&quot;&quot;</code>)
       est fournie pour le paramètre <code class="parameter">separator</code>.
       Précédemment, <span class="function"><strong>explode()</strong></span> retournait <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.explode-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>explode()</strong></span></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">// Exemple 1<br /></span><span style="color: #0000BB">$pizza  </span><span style="color: #007700">= </span><span style="color: #DD0000">"piece1 piece2 piece3 piece4 piece5 piece6"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$pieces </span><span style="color: #007700">= </span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">" "</span><span style="color: #007700">, </span><span style="color: #0000BB">$pizza</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$pieces</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">], </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">; </span><span style="color: #FF8000">// piece1<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$pieces</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">], </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">; </span><span style="color: #FF8000">// piece2<br /><br />// Exemple 2<br /></span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #DD0000">"foo:*:1023:1000::/home/foo:/bin/sh"</span><span style="color: #007700">;<br />list(</span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$pass</span><span style="color: #007700">, </span><span style="color: #0000BB">$uid</span><span style="color: #007700">, </span><span style="color: #0000BB">$gid</span><span style="color: #007700">, </span><span style="color: #0000BB">$gecos</span><span style="color: #007700">, </span><span style="color: #0000BB">$home</span><span style="color: #007700">, </span><span style="color: #0000BB">$shell</span><span style="color: #007700">) = </span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">":"</span><span style="color: #007700">, </span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">; </span><span style="color: #FF8000">// foo<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$pass</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">; </span><span style="color: #FF8000">// *<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Exemple de valeurs retournées par la fonction <span class="function"><strong>explode()</strong></span></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">/* Une chaîne qui ne contient pas de délimiteur va retourner un tableau<br />   contenant qu'un seul élément représentant la chaîne originale */<br /></span><span style="color: #0000BB">$input1 </span><span style="color: #007700">= </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$input2 </span><span style="color: #007700">= </span><span style="color: #DD0000">"hello,there"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$input3 </span><span style="color: #007700">= </span><span style="color: #DD0000">','</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">( </span><span style="color: #0000BB">explode</span><span style="color: #007700">( </span><span style="color: #DD0000">','</span><span style="color: #007700">, </span><span style="color: #0000BB">$input1 </span><span style="color: #007700">) );<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">( </span><span style="color: #0000BB">explode</span><span style="color: #007700">( </span><span style="color: #DD0000">','</span><span style="color: #007700">, </span><span style="color: #0000BB">$input2 </span><span style="color: #007700">) );<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">( </span><span style="color: #0000BB">explode</span><span style="color: #007700">( </span><span style="color: #DD0000">','</span><span style="color: #007700">, </span><span style="color: #0000BB">$input3 </span><span style="color: #007700">) );<br /><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(1)
(
    [0] =&gt; string(5) &quot;hello&quot;
)
array(2)
(
    [0] =&gt; string(5) &quot;hello&quot;
    [1] =&gt; string(5) &quot;there&quot;
)
array(2)
(
    [0] =&gt; string(0) &quot;&quot;
    [1] =&gt; string(0) &quot;&quot;
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Exemple #3 Exemple avec <span class="function"><strong>explode()</strong></span> et le paramètre <code class="parameter">limit</code></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">'one|two|three|four'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// limit positif<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">explode</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">2</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// limit négatif<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">explode</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">));<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; one
    [1] =&gt; two|three|four
)
Array
(
    [0] =&gt; one
    [1] =&gt; two
    [2] =&gt; three
)</pre>
</div>
    </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 notes" id="refsect1-function.explode-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">
 Cette fonction gère les chaînes binaires.
</span></p></blockquote>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.explode-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.preg-split.php" class="function" rel="rdfs-seeAlso">preg_split()</a> - &Eacute;clate une cha&icirc;ne par expression rationnelle</span></li>
    <li><span class="function"><a href="function.str-split.php" class="function" rel="rdfs-seeAlso">str_split()</a> - Convertit une cha&icirc;ne de caract&egrave;res en tableau</span></li>
    <li><span class="function"><a href="function.mb-split.php" class="function" rel="rdfs-seeAlso">mb_split()</a> - Scinde une cha&icirc;ne en tableau avec une expression rationnelle multioctets</span></li>
    <li><span class="function"><a href="function.str-word-count.php" class="function" rel="rdfs-seeAlso">str_word_count()</a> - Compte le nombre de mots utilis&eacute;s dans une cha&icirc;ne</span></li>
    <li><span class="function"><a href="function.strtok.php" class="function" rel="rdfs-seeAlso">strtok()</a> - Coupe une cha&icirc;ne en segments</span></li>
    <li><span class="function"><a href="function.implode.php" class="function" rel="rdfs-seeAlso">implode()</a> - Rassemble les &eacute;l&eacute;ments d'un tableau en une cha&icirc;ne</span></li>
   </ul>
  </p>
 </div>

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