function.strrpos.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 159 行

HTML
159
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Find position of last occurrence of a char in a string</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.strripos.html">strripos</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.strspn.html">strspn</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.strrpos" class="refentry"> <div class="refnamediv">  <h1 class="refname">strrpos</h1>  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">strrpos</span> &mdash; <span class="dc-title">Find position of last occurrence of a char in a string</span></p> </div>  <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">int</span> <span class="methodname"><b><b>strrpos</b></b></span>    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$haystack</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$needle</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$offset</tt></span>  ] )</div>  <p class="para rdfs-comment">   Returns the numeric position of the last occurrence of   <i><tt class="parameter">needle</tt></i> in the   <i><tt class="parameter">haystack</tt></i> string.  Note that the needle in   this case can only be a single character in PHP 4.  If a string is passed   as the needle, then only the first character of that string will   be used.  </p>  <p class="para">   If <i><tt class="parameter">needle</tt></i> is not found, returns <b><tt>FALSE</tt></b>.  </p>  <p class="para">   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:   <div class="informalexample">    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;in&nbsp;PHP&nbsp;4.0.0&nbsp;and&nbsp;newer:<br /></span><span style="color: #0000BB">$pos&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"b"</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$pos&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{&nbsp;</span><span style="color: #FF8000">//&nbsp;note:&nbsp;three&nbsp;equal&nbsp;signs<br />&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;not&nbsp;found...<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #FF8000">//&nbsp;in&nbsp;versions&nbsp;older&nbsp;than&nbsp;4.0.0:<br /></span><span style="color: #0000BB">$pos&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strrpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"b"</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">is_bool</span><span style="color: #007700">(</span><span style="color: #0000BB">$pos</span><span style="color: #007700">)&nbsp;&amp;&amp;&nbsp;!</span><span style="color: #0000BB">$pos</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;not&nbsp;found...<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p>  <p class="para">   If <i><tt class="parameter">needle</tt></i> is not a string, it is converted   to an integer and applied as the ordinal value of a character.  </p>  <blockquote><p><b class="note">Note</b>:    <span class="simpara">    As of PHP 5.0.0 <i><tt class="parameter">offset</tt></i> may    be specified to begin searching an arbitrary number of characters into    the string.  Negative values will stop searching at an arbitrary point    prior to the end of the string.   </span>  </p></blockquote>  <blockquote><p><b class="note">Note</b>:    <span class="simpara">    The <i><tt class="parameter">needle</tt></i> may be a string of more than one    character as of PHP 5.0.0.   </span>  </p></blockquote> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">haystack</tt></i></span>     <dd>      <p class="para">      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">needle</tt></i></span>     <dd>      <p class="para">      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">offset</tt></i></span>     <dd>      <p class="para">      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">     </p> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.strpos.html" class="function" rel="rdfs-seeAlso">strpos()</a></li>    <li class="member"><a href="function.strripos.html" class="function" rel="rdfs-seeAlso">strripos()</a></li>    <li class="member"><a href="function.strrchr.html" class="function" rel="rdfs-seeAlso">strrchr()</a></li>    <li class="member"><a href="function.substr.html" class="function" rel="rdfs-seeAlso">substr()</a></li>    <li class="member"><a href="function.stristr.html" class="function" rel="rdfs-seeAlso">stristr()</a></li>    <li class="member"><a href="function.strstr.html" class="function" rel="rdfs-seeAlso">strstr()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.strripos.html">strripos</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.strspn.html">strspn</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?