📄 function.stripos.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Find position of first occurrence of a case-insensitive 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.stripcslashes.html">stripcslashes</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.stripslashes.html">stripslashes</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.stripos" class="refentry"> <div class="refnamediv"> <h1 class="refname">stripos</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">stripos</span> — <span class="dc-title">Find position of first occurrence of a case-insensitive 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>stripos</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 first occurrence of <i><tt class="parameter">needle</tt></i> in the <i><tt class="parameter">haystack</tt></i> <a href="language.types.string.html" class="type string">string</a>. </p> <p class="para"> Unlike <a href="function.strpos.html" class="function">strpos()</a>, <b>stripos()</b> is case-insensitive. </p> </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"> The string to search in </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">needle</tt></i></span> <dd> <p class="para"> Note that the <i><tt class="parameter">needle</tt></i> may be a string of one or more characters. </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> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">offset</tt></i></span> <dd> <p class="para"> The optional <i><tt class="parameter">offset</tt></i> parameter allows you to specify which character in <i><tt class="parameter">haystack</tt></i> to start searching. The position returned is still relative to the beginning of <i><tt class="parameter">haystack</tt></i>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> If <i><tt class="parameter">needle</tt></i> is not found, <b>stripos()</b> will return <a href="language.types.boolean.html" class="type boolean">boolean</a> <b><tt>FALSE</tt></b>. </p> <div class="warning"><b class="warning">Warning</b><p class="simpara">This function mayreturn Boolean <b><tt>FALSE</tt></b>, but may also return a non-Boolean value whichevaluates to <b><tt>FALSE</tt></b>, such as <i>0</i> or"". Please read the section on <a href="language.types.boolean.html" class="link">Booleans</a> for moreinformation. Use <a href="language.operators.comparison.html" class="link">the ===operator</a> for testing the return value of thisfunction.</p></div> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>stripos()</b> examples</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$findme </span><span style="color: #007700">= </span><span style="color: #DD0000">'a'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$mystring1 </span><span style="color: #007700">= </span><span style="color: #DD0000">'xyz'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$mystring2 </span><span style="color: #007700">= </span><span style="color: #DD0000">'ABC'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$pos1 </span><span style="color: #007700">= </span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring1</span><span style="color: #007700">, </span><span style="color: #0000BB">$findme</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pos2 </span><span style="color: #007700">= </span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring2</span><span style="color: #007700">, </span><span style="color: #0000BB">$findme</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Nope, 'a' is certainly not in 'xyz'<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$pos1 </span><span style="color: #007700">=== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"The string '$findme' was not found in the string '$mystring1'"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// Note our use of ===. Simply == would not work as expected<br />// because the position of 'a' is the 0th (first) character.<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$pos2 </span><span style="color: #007700">!== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"We found '$findme' in '$mystring2' at position $pos2"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: <span class="simpara">This function isbinary-safe.</span></p></blockquote> </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.strrpos.html" class="function" rel="rdfs-seeAlso">strrpos()</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> <li class="member"><a href="function.strripos.html" class="function" rel="rdfs-seeAlso">strripos()</a></li> <li class="member"><a href="function.str-ireplace.html" class="function" rel="rdfs-seeAlso">str_ireplace()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.stripcslashes.html">stripcslashes</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.stripslashes.html">stripslashes</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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -