uTools-Manuals/docs/php/strstr.html
2019-04-08 23:22:26 +08:00

162 lines
6.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>查找字符串的首次出现</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.strstr" class="refentry">
<div class="refnamediv">
<h1 class="refname">strstr</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">strstr</span> &mdash; <span class="dc-title">查找字符串的首次出现</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.strstr-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>strstr</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$haystack</code></span>
, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$needle</code></span>
[, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$before_needle</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
] ) : <span class="type">string</span></div>
<p class="para rdfs-comment">
返回 <code class="parameter">haystack</code> 字符串从 <code class="parameter">needle</code> 第一次出现的位置开始到 <code class="parameter">haystack</code> 结尾的字符串。
</p>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
该函数区分大小写。如果想要不区分大小写,请使用 <span class="function"><a href="stristr.html" class="function">stristr()</a></span>
</p>
</p></blockquote>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
如果你仅仅想确定 <code class="parameter">needle</code> 是否存在于 <code class="parameter">haystack</code> 中,请使用速度更快、耗费内存更少的 <span class="function"><a href="strpos.html" class="function">strpos()</a></span> 函数。
</p>
</p></blockquote>
</div>
<div class="refsect1 parameters" id="refsect1-function.strstr-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> 不是一个字符串,那么它将被转化为整型并且作为字符的序号来使用。
</p>
</dd>
<dt>
<code class="parameter">before_needle</code></dt>
<dd>
<p class="para">
若为 <strong><code>TRUE</code></strong><span class="function"><strong>strstr()</strong></span> 将返回 <code class="parameter">needle</code><code class="parameter">haystack</code> 中的位置之前的部分。
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.strstr-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
返回字符串的一部分或者 <strong><code>FALSE</code></strong>(如果未发现 <code class="parameter">needle</code>)。
</p>
</div>
<div class="refsect1 changelog" id="refsect1-function.strstr-changelog">
<h3 class="title">更新日志</h3>
<p class="para">
<table class="doctable informaltable">
<thead>
<tr>
<th>版本</th>
<th>说明</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>5.3.0</td>
<td>
新增可选的 <code class="parameter">before_needle</code> 参数。
</td>
</tr>
<tr>
<td>4.3.0</td>
<td>
<span class="function"><strong>strstr()</strong></span> 成为二进制安全的。
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.strstr-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-5983">
<p><strong>Example #1 <span class="function"><strong>strstr()</strong></span> 范例</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$email&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'name@example.com'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$domain&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strstr</span><span style="color: #007700">(</span><span style="color: #0000BB">$email</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'@'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$domain</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;打印&nbsp;@example.com<br /><br /></span><span style="color: #0000BB">$user&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strstr</span><span style="color: #007700">(</span><span style="color: #0000BB">$email</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'@'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;&nbsp;PHP&nbsp;5.3.0&nbsp;<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;打印&nbsp;name<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.strstr-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="preg_match.html" class="function" rel="rdfs-seeAlso">preg_match()</a> - 执行匹配正则表达式</span></li>
<li class="member"><span class="function"><a href="stristr.html" class="function" rel="rdfs-seeAlso">stristr()</a> - strstr 函数的忽略大小写版本</span></li>
<li class="member"><span class="function"><a href="strpos.html" class="function" rel="rdfs-seeAlso">strpos()</a> - 查找字符串首次出现的位置</span></li>
<li class="member"><span class="function"><a href="strrchr.html" class="function" rel="rdfs-seeAlso">strrchr()</a> - 查找指定字符在字符串中的最后一次出现</span></li>
<li class="member"><span class="function"><a href="substr.html" class="function" rel="rdfs-seeAlso">substr()</a> - 返回字符串的子串</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>