📄 function.stristr.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Case-insensitive strstr</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.stripslashes.html">stripslashes</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.strlen.html">strlen</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.stristr" class="refentry"> <div class="refnamediv"> <h1 class="refname">stristr</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">stristr</span> — <span class="dc-title">Case-insensitive <a href="function.strstr.html" class="function">strstr()</a></span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><b><b>stristr</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$haystack</tt></span> , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$needle</tt></span> [, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$before_needle</tt></span> ] )</div> <p class="para rdfs-comment"> Returns all of <i><tt class="parameter">haystack</tt></i> from the first occurrence of <i><tt class="parameter">needle</tt></i> to the end. </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"> 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">before_needle</tt></i></span> <dd> <p class="para"> If <b><tt>TRUE</tt></b> (the default is <b><tt>FALSE</tt></b>), <b>stristr()</b> returns the part of the <i><tt class="parameter">haystack</tt></i> before the first occurence of the <i><tt class="parameter">needle</tt></i>. </p> </dd> </dt> </dl> </p> <p class="para"> <i><tt class="parameter">needle</tt></i> and <i><tt class="parameter">haystack</tt></i> are examined in a case-insensitive manner. </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the matched substring. If <i><tt class="parameter">needle</tt></i> is not found, returns <b><tt>FALSE</tt></b>. </p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.3.0</td> <td colspan="1" rowspan="1" align="left"> Added the optional parameter <i><tt class="parameter">before_needle</tt></i>. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">4.3.0</td> <td colspan="1" rowspan="1" align="left"> <b>stristr()</b> was made binary safe. </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>stristr()</b> example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /> $email </span><span style="color: #007700">= </span><span style="color: #DD0000">'USER@EXAMPLE.com'</span><span style="color: #007700">;<br /> echo </span><span style="color: #0000BB">stristr</span><span style="color: #007700">(</span><span style="color: #0000BB">$email</span><span style="color: #007700">, </span><span style="color: #DD0000">'e'</span><span style="color: #007700">); </span><span style="color: #FF8000">// outputs ER@EXAMPLE.com<br /> </span><span style="color: #007700">echo </span><span style="color: #0000BB">stristr</span><span style="color: #007700">(</span><span style="color: #0000BB">$email</span><span style="color: #007700">, </span><span style="color: #DD0000">'e'</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">); </span><span style="color: #FF8000">// As of PHP 5.3.0, outputs US<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #2 Testing if a string is found or not</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /> $string </span><span style="color: #007700">= </span><span style="color: #DD0000">'Hello World!'</span><span style="color: #007700">;<br /> if(</span><span style="color: #0000BB">stristr</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">, </span><span style="color: #DD0000">'earth'</span><span style="color: #007700">) === </span><span style="color: #0000BB">FALSE</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">'"earth" not found in string'</span><span style="color: #007700">;<br /> }<br /></span><span style="color: #FF8000">// outputs: "earth" not found in string<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #3 Using a non "string" needle</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /> $string </span><span style="color: #007700">= </span><span style="color: #DD0000">'APPLE'</span><span style="color: #007700">;<br /> echo </span><span style="color: #0000BB">stristr</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">, </span><span style="color: #0000BB">97</span><span style="color: #007700">); </span><span style="color: #FF8000">// 97 = lowercase a<br />// outputs: APPLE<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.strstr.html" class="function" rel="rdfs-seeAlso">strstr()</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.preg-match.html" class="function" rel="rdfs-seeAlso">preg_match()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.stripslashes.html">stripslashes</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.strlen.html">strlen</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 + -