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

contributors($setup);

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

 </div>
 
 <div class="refsect1 description" id="refsect1-function.strrpos-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strrpos</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>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strrpos-parameters">
  <h3 class="title">Параметри</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">
  До версії PHP 8.0.0, якщо параметр <code class="parameter">needle</code> не є рядком,
  він перетворюється на ціле число і розглядається як код символу. Ця поведінка
  є застарілою, починаючи з PHP 7.3.0. Вкрай не рекомендується на неї
  покладатися. Залежно від потрібної поведінки, параметр
  <code class="parameter">needle</code> необхідно привести до рядкового типу або
  обробити функцією <span class="function"><a href="function.chr.php" class="function">chr()</a></span>.
 </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 starts <code class="parameter">offset</code> bytes from
       the right instead of from the beginning of <code class="parameter">haystack</code>.
       The search is performed right to left, searching for the first
       occurrence of <code class="parameter">needle</code> from the selected byte.
       <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
        <p class="para">
         This is effectively looking for the last occurrence of
         <code class="parameter">needle</code> at or before the last
         <code class="parameter">offset</code> bytes.
        </p>
       </p></blockquote>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strrpos-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns the position where the needle exists relative to the beginning of
   the <code class="parameter">haystack</code> string (independent of search direction
   or offset).
   <blockquote class="note"><p><strong class="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 needle was not found.
  </p>
  <div class="warning"><strong class="warning">Увага</strong><p class="simpara">Ця функція може
повертати як логічне <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, так і не логічне значення, яке прирівнюється до
<strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. Докладніше про це описано в розділі <a href="language.types.boolean.php" class="link">Логічні типи даних</a>. Для перевірки
значення, яке повертає ця функція, використовується <a href="language.operators.comparison.php" class="link">оператор ===</a>.</p></div>
 </div>


 <div class="refsect1 errors" id="refsect1-function.strrpos-errors">
  <h3 class="title">Помилки/виключення</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.strrpos-changelog">
  <h3 class="title">Журнал змін</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версія</th>
      <th>Опис</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.0.0</td>
 <td>
  Тепер параметр <code class="parameter">needle</code> може бути порожнім рядком.
 </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.strrpos-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 Checking if a needle is in the haystack</strong></p>
    <div class="example-contents"><p>
     It is easy to mistake the return values for &quot;character found at
     position 0&quot; and &quot;character not found&quot;.  Here&#039;s how to detect
     the difference:
    </p></div>
    <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">'Elephpant'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$pos </span><span style="color: #007700">= </span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring</span><span style="color: #007700">, </span><span style="color: #DD0000">"b"</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">$pos </span><span style="color: #007700">=== </span><span style="color: #0000BB">false</span><span style="color: #007700">) { </span><span style="color: #FF8000">// note: three equal signs<br />    // not found...<br /></span><span style="color: #007700">}<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>Приклад #2 Searching with offsets</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$foo </span><span style="color: #007700">= </span><span style="color: #DD0000">"0123456789a123456789b123456789c"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Looking for '0' from the 0th byte (from the beginning)<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'0'</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// Looking for '0' from the 1st byte (after byte "0")<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'0'</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// Looking for '7' from the 21th byte (after byte 20)<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'7'</span><span style="color: #007700">, </span><span style="color: #0000BB">20</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// Looking for '7' from the 29th byte (after byte 28)<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'7'</span><span style="color: #007700">, </span><span style="color: #0000BB">28</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// Looking for '7' right to left from the 5th byte from the end<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'7'</span><span style="color: #007700">, -</span><span style="color: #0000BB">5</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// Looking for 'c' right to left from the 2nd byte from the end<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'c'</span><span style="color: #007700">, -</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// Looking for '9c' right to left from the 2nd byte from the end<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'9c'</span><span style="color: #007700">, -</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">int(0)
bool(false)
int(27)
bool(false)
int(17)
bool(false)
int(29)</pre>
</div>
   </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strrpos-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.strpos.php" class="function" rel="rdfs-seeAlso">strpos()</a> - Знаходить позицію першого входження підрядка в рядку</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.strripos.php" class="function" rel="rdfs-seeAlso">strripos()</a> - Find the position of the last occurrence of a case-insensitive 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.substr.php" class="function" rel="rdfs-seeAlso">substr()</a> - Return part of a string</span></li>
   </ul>
  </p>
 </div>


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