<?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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.strrchr.php',
    1 => 'strrchr',
    2 => '查找指定字符在字符串中的最后一次出现',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => '字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'function.strpos.php',
    1 => 'strpos',
  ),
  'next' => 
  array (
    0 => 'function.strrev.php',
    1 => 'strrev',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/strings/functions/strrchr.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.strrchr" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strrchr</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">strrchr</span> &mdash; <span class="dc-title">查找指定字符在字符串中的最后一次出现</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.strrchr-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strrchr</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.boolean.php" class="type bool">bool</a></span> <code class="parameter">$before_needle</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   该函数返回 <code class="parameter">haystack</code> 字符串中的一部分，这部分以 <code class="parameter">needle</code>
   的最后出现位置开始，直到 <code class="parameter">haystack</code> 末尾。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strrchr-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">haystack</code></dt>
     <dd>
      <p class="para">
       在该字符串中查找。
      </p>
     </dd>
    
    
     <dt><code class="parameter">needle</code></dt>
     <dd>
      <p class="para">
       如果 <code class="parameter">needle</code> 包含了多个字符，那么仅使用第一个字符。该行为不同于 <span class="function"><a href="function.strstr.php" class="function">strstr()</a></span>。
      </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">before_needle</code></dt>
     <dd>
      <p class="para">
       如果为 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>，<span class="function"><strong>strrchr()</strong></span> 返回最后一次出现 <code class="parameter">needle</code>
       之前的 <code class="parameter">haystack</code> 部分（不包括 needle）。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strrchr-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   该函数返回字符串的一部分。如果 <code class="parameter">needle</code> 未被找到，返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.strrchr-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       新增 <code class="parameter">before_needle</code> 参数。
      </td>
     </tr>

     <tr>
 <td>8.0.0</td>
 <td>
  <code class="parameter">needle</code> 现在接受空字符串。
 </td>
</tr>

     <tr>
      <td>8.0.0</td>
      <td>
       不再支持将 <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> 作为 <code class="parameter">needle</code> 传递。
      </td>
     </tr>

     <tr>
      <td>7.3.0</td>
      <td>
       弃用将 <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> 作为 <code class="parameter">needle</code> 传递。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.strrchr-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>strrchr()</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 />$ext </span><span style="color: #007700">= </span><span style="color: #0000BB">strrchr</span><span style="color: #007700">(</span><span style="color: #DD0000">'somefile.txt'</span><span style="color: #007700">, </span><span style="color: #DD0000">'.'</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"file extension: </span><span style="color: #0000BB">$ext</span><span style="color: #DD0000"> \n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$ext </span><span style="color: #007700">= </span><span style="color: #0000BB">$ext </span><span style="color: #007700">? </span><span style="color: #0000BB">strtolower</span><span style="color: #007700">(</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$ext</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">)) : </span><span style="color: #DD0000">''</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"file extension: </span><span style="color: #0000BB">$ext</span><span style="color: #DD0000">"</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">file extension: .txt
file extension: txt</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.strrchr-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">此函数可安全用于二进制对象。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strrchr-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.strstr.php" class="function" rel="rdfs-seeAlso">strstr()</a> - 查找字符串的首次出现</span></li>
    <li><span class="function"><a href="function.strrpos.php" class="function" rel="rdfs-seeAlso">strrpos()</a> - 计算指定字符串在目标字符串中最后一次出现的位置</span></li>
   </ul>
  </p>
 </div>


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