<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.str-word-count.php',
    1 => 'str_word_count',
    2 => '返回字符串中单词的使用情况',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => '字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'function.str-starts-with.php',
    1 => 'str_starts_with',
  ),
  'next' => 
  array (
    0 => 'function.strcasecmp.php',
    1 => 'strcasecmp',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/strings/functions/str-word-count.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.str-word-count" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">str_word_count</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">str_word_count</span> &mdash; <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"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$format</code><span class="initializer"> = 0</span></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$characters</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span></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">
   对于这个函数的目的来说，单词的定义是一个与区域设置相关的字符串。这个字符串可以包含字母字符，也可以包含
   &quot;&#039;&quot; 和 &quot;-&quot; 字符（但不能以这两个字符开始）。
   请注意，不支持多字节编码的字符串。
  </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">characters</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>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">characters</code> 可为空（Nullable）类型。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.str-word-count-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>str_word_count()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例会输出：</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [0] =&gt; Hello
    [1] =&gt; fri
    [2] =&gt; nd
    [3] =&gt; you&#039;re
    [4] =&gt; looking
    [5] =&gt; good
    [6] =&gt; today
)

Array
(
    [0] =&gt; Hello
    [6] =&gt; fri
    [10] =&gt; nd
    [14] =&gt; you&#039;re
    [29] =&gt; looking
    [46] =&gt; good
    [51] =&gt; today
)

Array
(
    [0] =&gt; Hello
    [1] =&gt; fri3nd
    [2] =&gt; you&#039;re
    [3] =&gt; looking
    [4] =&gt; good
    [5] =&gt; 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><span class="function"><a href="function.explode.php" class="function" rel="rdfs-seeAlso">explode()</a> - 使用一个字符串分割另一个字符串</span></li>
    <li><span class="function"><a href="function.preg-split.php" class="function" rel="rdfs-seeAlso">preg_split()</a> - 通过一个正则表达式分隔字符串</span></li>
    <li><span class="function"><a href="function.count-chars.php" class="function" rel="rdfs-seeAlso">count_chars()</a> - 返回字符串所用字符的信息</span></li>
    <li><span class="function"><a href="function.substr-count.php" class="function" rel="rdfs-seeAlso">substr_count()</a> - 计算字串出现的次数</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>