<?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.strpos.php',
    1 => 'strpos',
    2 => 'Cherche la position de la premi&egrave;re occurrence dans une cha&icirc;ne',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'Fonctions sur les cha&icirc;nes de caract&egrave;res',
  ),
  'prev' => 
  array (
    0 => 'function.strpbrk.php',
    1 => 'strpbrk',
  ),
  'next' => 
  array (
    0 => 'function.strrchr.php',
    1 => 'strrchr',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/strings/functions/strpos.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.strpos" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strpos</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">strpos</span> &mdash; <span class="dc-title">Cherche la position de la première occurrence dans une chaîne</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.strpos-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strpos</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$haystack</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$needle</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$offset</code><span class="initializer"> = 0</span></span>): <span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Cherche la position numérique de la première occurrence de
   <code class="parameter">needle</code> dans la <a href="language.types.string.php" class="link">chaîne de caractères</a>
   <code class="parameter">haystack</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strpos-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">haystack</code></dt>
     <dd>
      <p class="para">
       La chaîne dans laquelle on doit chercher.
      </p>
     </dd>
    
    
     <dt><code class="parameter">needle</code></dt>
     <dd>
      <p class="para">
       La chaîne à rechercher.
      </p>
      
 <p class="para">
  Antérieur à PHP 8.0.0, si <code class="parameter">needle</code> n&#039;est pas une chaîne de caractères,
  elle est convertie en un entier et appliqué en tant que valeur ordinal d&#039;un caractère.
  Ce comportement est obsolète à partir de PHP 7.3.0, et se fier à celui-ci
  est fortement déconseillé. En fonction du comportement attendu,
  <code class="parameter">needle</code> doit être transtypé explicitement en une chaîne de caractère,
  ou un appel explicite à <span class="function"><a href="function.chr.php" class="function">chr()</a></span> doit être exécuté.
 </p>

     </dd>
    
    
     <dt><code class="parameter">offset</code></dt>
     <dd>
      <p class="para">
       Si spécifié, la recherche commencera à partir de ce
       nombre de caractères compté depuis le début de la chaîne.
       Si ce nombre est négatif, la recherche commencera en utilisant
       ce nombre de caractères mais en commençant par la fin de la chaîne.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strpos-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne la position numérique de l&#039;occurrence relativement
   au début de la chaîne <code class="parameter">haystack</code>
   (indépendamment de l&#039;<code class="parameter">offset</code>).
   Notez également que la position dans la chaîne commence
   à <code class="literal">0</code>, et non pas à <code class="literal">1</code>.
  </p>
  <p class="para">
   Retourne <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si l&#039;occurrence n&#039;a pas été trouvée.
  </p>
  <div class="warning"><strong class="warning">Avertissement</strong><p class="simpara">
 Cette fonction peut retourner <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, mais elle peut aussi retourner une valeur équivalent à <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
 Veuillez lire la section sur les <a href="language.types.boolean.php" class="link">booléens</a> pour plus d&#039;informations.
 Utilisez l&#039;<a href="language.operators.comparison.php" class="link">opérateur ===</a>
 pour tester la valeur de retour exacte de cette fonction.
</p></div>
 </div>


 <div class="refsect1 errors" id="refsect1-function.strpos-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     Si <code class="parameter">offset</code> est supérieur à la longueur de
     <code class="parameter">haystack</code>, une
     <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> sera levée.
    </span>
   </li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.strpos-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>
  <code class="parameter">needle</code> accepte désormais une chaîne vide.
 </td>
</tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Passer un <a href="language.types.integer.php" class="link">entier</a> comme <code class="parameter">needle</code> n&#039;est plus supporté.
      </td>
     </tr>

     <tr>
      <td>7.3.0</td>
      <td>
       Passer un <a href="language.types.integer.php" class="link">entier</a> comme <code class="parameter">needle</code> a été
       rendu obsolète.
      </td>
     </tr>

     <tr>
      <td>7.1.0</td>
      <td>
       Ajout du support des nombres négatifs pour le paramètre <code class="parameter">offset</code>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.strpos-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Avec <code class="literal">===</code></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$mystring </span><span style="color: #007700">= </span><span style="color: #DD0000">'abc'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$findme   </span><span style="color: #007700">= </span><span style="color: #DD0000">'a'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$pos </span><span style="color: #007700">= </span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring</span><span style="color: #007700">, </span><span style="color: #0000BB">$findme</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Notez notre utilisation de ===.  == ne fonctionnerait pas comme attendu<br />// car la position de 'a' est la 0-ième (premier) caractère.<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$pos </span><span style="color: #007700">=== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"La chaîne '</span><span style="color: #0000BB">$findme</span><span style="color: #DD0000">' ne se trouve pas dans la chaîne '</span><span style="color: #0000BB">$mystring</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">"La chaine '</span><span style="color: #0000BB">$findme</span><span style="color: #DD0000">' a été trouvée dans la chaîne '</span><span style="color: #0000BB">$mystring</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br />    echo </span><span style="color: #DD0000">" et débute à la position </span><span style="color: #0000BB">$pos</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>

   <div class="example" id="example-2">
    <p><strong>Exemple #2 Avec !==</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$mystring </span><span style="color: #007700">= </span><span style="color: #DD0000">'abc'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$findme   </span><span style="color: #007700">= </span><span style="color: #DD0000">'a'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$pos </span><span style="color: #007700">= </span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring</span><span style="color: #007700">, </span><span style="color: #0000BB">$findme</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Notez notre utilisation de !==.  != ne fonctionnerait pas comme attendu<br />// car la position de 'a' est la 0-ième (premier) caractère.<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$pos </span><span style="color: #007700">!== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"La chaine '</span><span style="color: #0000BB">$findme</span><span style="color: #DD0000">' a été trouvée dans la chaîne '</span><span style="color: #0000BB">$mystring</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br />    echo </span><span style="color: #DD0000">" et débute à la position </span><span style="color: #0000BB">$pos</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">"La chaîne '</span><span style="color: #0000BB">$findme</span><span style="color: #DD0000">' ne se trouve pas dans la chaîne '</span><span style="color: #0000BB">$mystring</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>

   <div class="example" id="example-3">
    <p><strong>Exemple #3 Utiliser un offset</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">// Nous pouvons chercher le caractère, et ignorer tout ce qui est avant l'offset<br /></span><span style="color: #0000BB">$newstring </span><span style="color: #007700">= </span><span style="color: #DD0000">'abcdef abcdef'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$pos </span><span style="color: #007700">= </span><span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$newstring</span><span style="color: #007700">, </span><span style="color: #DD0000">'a'</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">); </span><span style="color: #FF8000">// $pos = 7, non pas 0<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$pos</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.strpos-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.strpos-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.stripos.php" class="function" rel="rdfs-seeAlso">stripos()</a> - Recherche la position de la premi&egrave;re occurrence dans une cha&icirc;ne, sans tenir compte de la casse</span></li>
    <li><span class="function"><a href="function.str-contains.php" class="function" rel="rdfs-seeAlso">str_contains()</a> - D&eacute;termine si une cha&icirc;ne contient une sous-cha&icirc;ne donn&eacute;e</span></li>
    <li><span class="function"><a href="function.str-ends-with.php" class="function" rel="rdfs-seeAlso">str_ends_with()</a> - D&eacute;termine si une cha&icirc;ne se termine par une sous-cha&icirc;ne donn&eacute;e</span></li>
    <li><span class="function"><a href="function.str-starts-with.php" class="function" rel="rdfs-seeAlso">str_starts_with()</a> - D&eacute;termine si une cha&icirc;ne commence par une sous-cha&icirc;ne donn&eacute;e</span></li>
    <li><span class="function"><a href="function.strrpos.php" class="function" rel="rdfs-seeAlso">strrpos()</a> - Cherche la position de la derni&egrave;re occurrence d'une sous-cha&icirc;ne dans une cha&icirc;ne</span></li>
    <li><span class="function"><a href="function.strripos.php" class="function" rel="rdfs-seeAlso">strripos()</a> - Cherche la position de la derni&egrave;re occurrence d'une cha&icirc;ne contenue
   dans une autre, de fa&ccedil;on insensible &agrave; la casse</span></li>
    <li><span class="function"><a href="function.strstr.php" class="function" rel="rdfs-seeAlso">strstr()</a> - Trouve la premi&egrave;re occurrence dans une cha&icirc;ne</span></li>
    <li><span class="function"><a href="function.strpbrk.php" class="function" rel="rdfs-seeAlso">strpbrk()</a> - Recherche un ensemble de caract&egrave;res dans une cha&icirc;ne de caract&egrave;res</span></li>
    <li><span class="function"><a href="function.substr.php" class="function" rel="rdfs-seeAlso">substr()</a> - Retourne un segment de cha&icirc;ne</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>
   </ul>
  </p>
 </div>


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