<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.str-word-count.php',
    1 => 'str_word_count',
    2 => '文字列に使用されている単語についての情報を返す',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String 関数',
  ),
  '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' => 'ja',
    '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">
   この関数を使用するうえで、&#039;単語&#039; は「ロケールに依存したアルファベットから
   なる文字列で、その先頭以外の部分に &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">
       &#039;単語&#039; とみなされる文字に追加する文字のリスト。
      </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); ?>