mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
201 lines
8.1 KiB
HTML
201 lines
8.1 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.str-word-count" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">str_word_count</h1>
|
|
<p class="verinfo">(PHP 4 >= 4.3.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">str_word_count</span> — <span class="dc-title">返回字符串中单词的使用情况</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.str-word-count-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>str_word_count</strong></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">$format</code><span class="initializer"> = 0</span></span>
|
|
[, <span class="methodparam"><span class="type">string</span> <code class="parameter">$charlist</code></span>
|
|
]] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
统计 <code class="parameter">string</code> 中单词的数量。如果可选的参数 <code class="parameter">format</code> 没有被指定,那么返回值是一个代表单词数量的整型数。如果指定了 <code class="parameter">format</code> 参数,返回值将是一个数组,数组的内容则取决于 <code class="parameter">format</code> 参数。<code class="parameter">format</code> 的可能值和相应的输出结果如下所列。
|
|
</p>
|
|
<p class="para">
|
|
对于这个函数的目的来说,单词的定义是一个与区域设置相关的字符串。这个字符串可以包含字母字符,也可以包含 "'" 和 "-" 字符(但不能以这两个字符开始)。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.str-word-count-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">string</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
字符串。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">format</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
指定函数的返回值。当前支持的值如下:
|
|
<ul class="itemizedlist">
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
0 - 返回单词数量
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
1 - 返回一个包含 <code class="parameter">string</code> 中全部单词的数组
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
2 - 返回关联数组。数组的键是单词在 <code class="parameter">string</code> 中出现的数值位置,数组的值是这个单词
|
|
</span>
|
|
</li>
|
|
</ul>
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">charlist</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
附加的字符串列表,其中的字符将被视为单词的一部分。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.str-word-count-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
返回一个数组或整型数,这取决于 <code class="parameter">format</code> 参数的选择。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.str-word-count-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.1.0</td>
|
|
<td>
|
|
新增 <code class="parameter">charlist</code> 参数。
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.str-word-count-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-5961">
|
|
<p><strong>Example #1 <span class="function"><strong>str_word_count()</strong></span> 范例</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /><br />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">"Hello fri3nd, you're<br /> looking good today!"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">str_word_count</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">str_word_count</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">str_word_count</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #DD0000">'àáãç3'</span><span style="color: #007700">));<br /><br />echo </span><span style="color: #0000BB">str_word_count</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">);<br /><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] => Hello
|
|
[1] => fri
|
|
[2] => nd
|
|
[3] => you're
|
|
[4] => looking
|
|
[5] => good
|
|
[6] => today
|
|
)
|
|
|
|
Array
|
|
(
|
|
[0] => Hello
|
|
[6] => fri
|
|
[10] => nd
|
|
[14] => you're
|
|
[29] => looking
|
|
[46] => good
|
|
[51] => today
|
|
)
|
|
|
|
Array
|
|
(
|
|
[0] => Hello
|
|
[1] => fri3nd
|
|
[2] => you're
|
|
[3] => looking
|
|
[4] => good
|
|
[5] => today
|
|
)
|
|
|
|
7
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.str-word-count-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<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="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="count_chars.html" class="function" rel="rdfs-seeAlso">count_chars()</a> - 返回字符串所用字符的信息</span></li>
|
|
<li class="member"><span class="function"><a href="substr_count.html" class="function" rel="rdfs-seeAlso">substr_count()</a> - 计算字串出现的次数</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |