<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.strrchr.php',
    1 => 'strrchr',
    2 => '文字列中に文字が最後に現れる場所を取得する',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String 関数',
  ),
  'prev' => 
  array (
    0 => 'function.strpos.php',
    1 => 'strpos',
  ),
  'next' => 
  array (
    0 => 'function.strrev.php',
    1 => 'strrev',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    '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">
  PHP 8.0.0 より前のバージョンでは、<code class="parameter">needle</code> が文字列でない場合、
  数値に変換され、文字のコードポイントとして扱われていました。
  この振る舞いは PHP 7.3.0 以降では推奨されないので、
  この機能を使用しないことを強く推奨します。
  意図する動作に応じて、
  <code class="parameter">needle</code> を string に明示的にキャストするか、
  明示的に <span class="function"><a href="function.chr.php" class="function">chr()</a></span> 関数を呼び出すべきでしょう。
 </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> にすると、
       <code class="parameter">haystack</code> の中で
       最後に <code class="parameter">needle</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>
       <code class="parameter">needle</code> に数値を渡すことはサポートされなくなりました。
      </td>
     </tr>

     <tr>
      <td>7.3.0</td>
      <td>
       <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); ?>