<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.strripos.php',
    1 => 'strripos',
    2 => 'Find the position of the last occurrence of a case-insensitive substring in a string',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Functions',
  ),
  'prev' => 
  array (
    0 => 'function.strrev.php',
    1 => 'strrev',
  ),
  'next' => 
  array (
    0 => 'function.strrpos.php',
    1 => 'strrpos',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/strings/functions/strripos.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.strripos" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strripos</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">strripos</span> &mdash; <span class="dc-title">Find the position of the last occurrence of a case-insensitive substring in a string</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.strripos-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strripos</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">
   Find the numeric position of the last occurrence of
   <code class="parameter">needle</code> in the <code class="parameter">haystack</code> string.
  </p>
  <p class="para">
   Unlike the <span class="function"><a href="function.strrpos.php" class="function">strrpos()</a></span>, <span class="function"><strong>strripos()</strong></span> is
   case-insensitive.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strripos-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">haystack</code></dt>
     <dd>
      <p class="para">
       The string to search in.
      </p>
     </dd>
    
    
     <dt><code class="parameter">needle</code></dt>
     <dd>
      <p class="para">
       The string to search for.
      </p>
      
 <p class="para">
  Prior to PHP 8.0.0, if <code class="parameter">needle</code> is not a string, it is converted
  to an integer and applied as the ordinal value of a character.
  This behavior is deprecated as of PHP 7.3.0, and relying on it is highly
  discouraged. Depending on the intended behavior, the
  <code class="parameter">needle</code> should either be explicitly cast to string,
  or an explicit call to <span class="function"><a href="function.chr.php" class="function">chr()</a></span> should be performed.
 </p>

     </dd>
    
    
     <dt><code class="parameter">offset</code></dt>
     <dd>
      <p class="para">
       If zero or positive, the search is performed left to right skipping the
       first <code class="parameter">offset</code> bytes of the
       <code class="parameter">haystack</code>.
      </p>
      <p class="para">
       If negative, the search is performed right to left skipping the
       last <code class="parameter">offset</code> bytes of the
       <code class="parameter">haystack</code> and searching for the first occurrence
       of <code class="parameter">needle</code>.
       <blockquote class="note"><p><strong class="note">Note</strong>: 
        <p class="para">
         This is effectively looking for the last occurrence of
         <code class="parameter">needle</code> before the last
         <code class="parameter">offset</code> bytes.
        </p>
       </p></blockquote>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strripos-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the position where the <code class="parameter">needle</code> exists relative to the beginning of
   the <code class="parameter">haystack</code> string (independent of search direction
   or <code class="parameter">offset</code>).
   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <span class="simpara">
     String positions start at 0, and not 1.
    </span>
   </p></blockquote>
  </p>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if the <code class="parameter">needle</code> was not found.
  </p>
  <div class="warning"><strong class="warning">Warning</strong><p class="simpara">This function may
return Boolean <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, but may also return a non-Boolean value which
evaluates to <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. Please read the section on <a href="language.types.boolean.php" class="link">Booleans</a> for more
information. Use <a href="language.operators.comparison.php" class="link">the ===
operator</a> for testing the return value of this
function.</p></div>
 </div>


 <div class="refsect1 errors" id="refsect1-function.strripos-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     If <code class="parameter">offset</code> is greater than the length of
     <code class="parameter">haystack</code>, a
     <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> will be thrown.
    </span>
   </li>
  </ul>
 </div>


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

    </thead>

    <tbody class="tbody">
     
 <tr>
  <td>8.2.0</td>
  <td>
   Case folding no longer depends on the locale set with
   <span class="function"><a href="function.setlocale.php" class="function">setlocale()</a></span>. Only ASCII case folding will be done.
   Non-ASCII bytes will be compared by their byte value.
  </td>
 </tr>


     <tr>
 <td>8.0.0</td>
 <td>
  <code class="parameter">needle</code> now accepts an empty string.
 </td>
</tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Passing an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> as <code class="parameter">needle</code> is no longer supported.
      </td>
     </tr>

     <tr>
      <td>7.3.0</td>
      <td>
       Passing an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> as <code class="parameter">needle</code> has been deprecated.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.strripos-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 A simple <span class="function"><strong>strripos()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$haystack </span><span style="color: #007700">= </span><span style="color: #DD0000">'ababcd'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$needle   </span><span style="color: #007700">= </span><span style="color: #DD0000">'aB'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$pos      </span><span style="color: #007700">= </span><span style="color: #0000BB">strripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$haystack</span><span style="color: #007700">, </span><span style="color: #0000BB">$needle</span><span style="color: #007700">);<br /><br />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">"Sorry, we did not find `</span><span style="color: #0000BB">$needle</span><span style="color: #DD0000">` in `</span><span style="color: #0000BB">$haystack</span><span style="color: #DD0000">`"</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">"Congratulations!\n"</span><span style="color: #007700">;<br />    echo </span><span style="color: #DD0000">"We found the last `</span><span style="color: #0000BB">$needle</span><span style="color: #DD0000">` in `</span><span style="color: #0000BB">$haystack</span><span style="color: #DD0000">` at position `</span><span style="color: #0000BB">$pos</span><span style="color: #DD0000">`"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Congratulations!
We found the last `aB` in `ababcd` at position `2`</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strripos-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.strpos.php" class="function" rel="rdfs-seeAlso">strpos()</a> - Find the position of the first occurrence of a substring in a string</span></li>
    <li><span class="function"><a href="function.stripos.php" class="function" rel="rdfs-seeAlso">stripos()</a> - Find the position of the first occurrence of a case-insensitive substring in a string</span></li>
    <li><span class="function"><a href="function.strrpos.php" class="function" rel="rdfs-seeAlso">strrpos()</a> - Find the position of the last occurrence of a substring in a string</span></li>
    <li><span class="function"><a href="function.strrchr.php" class="function" rel="rdfs-seeAlso">strrchr()</a> - Find the last occurrence of a character in a string</span></li>
    <li><span class="function"><a href="function.stristr.php" class="function" rel="rdfs-seeAlso">stristr()</a> - Case-insensitive strstr</span></li>
    <li><span class="function"><a href="function.substr.php" class="function" rel="rdfs-seeAlso">substr()</a> - Return part of a string</span></li>
   </ul>
  </p>
 </div>


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