mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-17 21:16:57 +08:00
161 lines
7.2 KiB
HTML
161 lines
7.2 KiB
HTML
<!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.spliti" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">spliti</h1>
|
|
<p class="verinfo">(PHP 4 >= 4.0.1, PHP 5)</p><p class="refpurpose"><span class="refname">spliti</span> — <span class="dc-title">用正则表达式不区分大小写将字符串分割到数组中</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.spliti-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>spliti</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$limit</code><span class="initializer"> = -1</span></span>
|
|
] ) : <span class="type">array</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
用正则表达式将一个 <code class="parameter">string</code> 分割成数组。
|
|
</p>
|
|
<p class="para">
|
|
本函数和 <span class="function"><a href="split.html" class="function">split()</a></span> 相同,只除了在匹配字母字符时忽略大小写的区别。
|
|
</p>
|
|
<div class="warning"><strong class="warning">Warning</strong><p class="simpara">自 PHP 5.3.0
|
|
起,已经<em class="emphasis">废弃</em>此函数。强烈建议不要应用此函数 。</p></div>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.spliti-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">pattern</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
大小写不敏感的正则表达式。
|
|
</p>
|
|
<p class="para">
|
|
If you want to split on any of the characters which are considered
|
|
special by regular expressions, you'll need to escape them first. If
|
|
you think <span class="function"><strong>spliti()</strong></span> (or any other regex function, for
|
|
that matter) is doing something weird, please read the file
|
|
<var class="filename">regex.7</var>, included in the
|
|
<var class="filename">regex/</var> subdirectory of the PHP distribution. It's
|
|
in manpage format, so you'll want to do something along the lines of
|
|
<strong class="command">man /usr/local/src/regex/regex.7</strong> in order to read it.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">string</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
输入的字符。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">limit</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
如果设置了 <code class="parameter">limit</code>,返回的数组最多会包含 <code class="parameter">limit</code> 个元素,最后一个元素包含了剩下的全部 <code class="parameter">string</code>。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.spliti-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
Returns an array of strings, each of which is a substring of
|
|
<code class="parameter">string</code> formed by splitting it on boundaries formed
|
|
by the case insensitive regular expression <code class="parameter">pattern</code>.
|
|
</p>
|
|
<p class="para">
|
|
If there are <span class="replaceable">n</span> occurrences of
|
|
<code class="parameter">pattern</code>, the returned array will contain
|
|
<em><span class="replaceable">n</span>+1</em> items. For example, if
|
|
there is no occurrence of <code class="parameter">pattern</code>, an array with
|
|
only one element will be returned. Of course, this is also true if
|
|
<code class="parameter">string</code> is empty. If an error occurs,
|
|
<span class="function"><strong>spliti()</strong></span> returns <strong><code>FALSE</code></strong>.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.spliti-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
本例用 'a' 做分隔符来分割一个字符串:
|
|
<div class="example" id="example-5889">
|
|
<p><strong>Example #1 <span class="function"><strong>spliti()</strong></span> 例子</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$string </span><span style="color: #007700">= </span><span style="color: #DD0000">"aBBBaCCCADDDaEEEaGGGA"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$chunks </span><span style="color: #007700">= </span><span style="color: #0000BB">spliti </span><span style="color: #007700">(</span><span style="color: #DD0000">"a"</span><span style="color: #007700">, </span><span style="color: #0000BB">$string</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$chunks</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程会输出:</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
Array
|
|
(
|
|
[0] =>
|
|
[1] => BBB
|
|
[2] => CCC
|
|
[3] => DDD
|
|
[4] => EEEaGGGA
|
|
)
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 notes" id="refsect1-function.spliti-notes">
|
|
<h3 class="title">注释</h3>
|
|
<blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">在 PHP 5.3.0
|
|
中,已放弃使用 regex 扩展而建议使用 <a href="book.pcre.html" class="link">PCRE 扩展</a>。调用此函数将会发出
|
|
<strong><code>E_DEPRECATED</code></strong> 通知。参见“<a href="reference.pcre.pattern.posix.html" class="link">差异列表</a>”可帮助你转为使用 PCRE。</p></p></blockquote>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.spliti-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="preg_split.html" class="function" rel="rdfs-seeAlso">preg_split()</a> - 通过一个正则表达式分隔字符串</span></li>
|
|
<li class="member"><span class="function"><a href="split.html" class="function" rel="rdfs-seeAlso">split()</a> - 用正则表达式将字符串分割到数组中</span></li>
|
|
<li class="member"><span class="function"><a href="explode.html" class="function" rel="rdfs-seeAlso">explode()</a> - 使用一个字符串分割另一个字符串</span></li>
|
|
<li class="member"><span class="function"><a href="implode.html" class="function" rel="rdfs-seeAlso">implode()</a> - 将一个一维数组的值转化为字符串</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |