Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 9855

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>str_word_count</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="String 字符串处理函数"
HREF="ref.strings.html"><LINK
REL="PREVIOUS"
TITLE="str_split"
HREF="function.str-split.html"><LINK
REL="NEXT"
TITLE="strcasecmp"
HREF="function.strcasecmp.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.str-split.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.strcasecmp.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.str-word-count"
></A
>str_word_count</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN227302"
></A
><P
>    (PHP 4 &#62;= 4.3.0, PHP 5)</P
>str_word_count&nbsp;--&nbsp;
   Return information about words used in a string
  </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN227305"
></A
><H2
>说明</H2
>mixed <B
CLASS="methodname"
>str_word_count</B
> ( string string [, int format [, string charlist]] )<BR
></BR
><P
>&#13;   Counts the number of words inside <CODE
CLASS="parameter"
>string</CODE
>. 
   If the optional <CODE
CLASS="parameter"
>format</CODE
> is not specified, then 
   the return value will be an integer representing the number of words 
   found. In the event the <CODE
CLASS="parameter"
>format</CODE
> is specified, the return
   value will be an array, content of which is dependent on the 
   <CODE
CLASS="parameter"
>format</CODE
>. The possible value for the 
   <CODE
CLASS="parameter"
>format</CODE
> and the resultant outputs are listed below.
  </P
><P
>&#13;   For the purpose of this function, 'word' is defined as a locale dependent
   string containing alphabetic characters, which also may contain, but not start
   with "'" and "-" characters.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN227326"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>string</CODE
></DT
><DD
><P
>&#13;       The string
      </P
></DD
><DT
><CODE
CLASS="parameter"
>format</CODE
></DT
><DD
><P
>&#13;       Specify the return value of this function. The current supported values
       are:
       <P
></P
><UL
><LI
><P
>&#13;          0 - returns the number of words found
         </P
></LI
><LI
><P
>&#13;          1 - returns an array containing all the words found inside the
          <CODE
CLASS="parameter"
>string</CODE
>
         </P
></LI
><LI
><P
>&#13;          2 - returns an associative array, where the key is the numeric
          position of the word inside the <CODE
CLASS="parameter"
>string</CODE
> and
          the value is the actual word itself
         </P
></LI
></UL
>
      </P
></DD
><DT
><CODE
CLASS="parameter"
>charlist</CODE
></DT
><DD
><P
>&#13;       A list of additional characters which will be considered as 'word'
      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN227354"
></A
><H2
>返回值</H2
><P
>&#13;   Returns an array or an integer, depending on the
   <CODE
CLASS="parameter"
>format</CODE
> chosen.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN227358"
></A
><H2
>更新日志</H2
><P
>&#13;   <DIV
CLASS="informaltable"
><P
></P
><A
NAME="AEN227361"
></A
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>版本</TH
><TH
>说明</TH
></TR
></THEAD
><TBODY
><TR
><TD
>5.1.0</TD
><TD
>&#13;        Added the <CODE
CLASS="parameter"
>charlist</CODE
> parameter
       </TD
></TR
></TBODY
></TABLE
><P
></P
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN227372"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN227375"
></A
><P
><B
>例 1. A <B
CLASS="function"
>str_word_count()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /><br />$str </font><font color="#007700">= </font><font color="#DD0000">"Hello fri3nd, you're<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;looking&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;good today!"</font><font color="#007700">;<br /><br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">str_word_count</font><font color="#007700">(</font><font color="#0000BB">$str</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">));<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">str_word_count</font><font color="#007700">(</font><font color="#0000BB">$str</font><font color="#007700">, </font><font color="#0000BB">2</font><font color="#007700">));<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">str_word_count</font><font color="#007700">(</font><font color="#0000BB">$str</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#DD0000">'àáãç3'</font><font color="#007700">));<br /><br />echo </font><font color="#0000BB">str_word_count</font><font color="#007700">(</font><font color="#0000BB">$str</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>Array
(
    [0] =&#62; Hello
    [1] =&#62; fri
    [2] =&#62; nd
    [3] =&#62; you're
    [4] =&#62; looking
    [5] =&#62; good
    [6] =&#62; today
)

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

Array
(
    [0] =&#62; Hello
    [1] =&#62; fri3nd
    [2] =&#62; you're
    [3] =&#62; looking
    [4] =&#62; good
    [5] =&#62; today
)

7</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN227381"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.explode.html"
><B
CLASS="function"
>explode()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.preg-split.html"
><B
CLASS="function"
>preg_split()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.split.html"
><B
CLASS="function"
>split()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.count-chars.html"
><B
CLASS="function"
>count_chars()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.substr-count.html"
><B
CLASS="function"
>substr_count()</B
></A
></TD
></TR
></TBODY
></TABLE
><P
></P
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.str-split.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.strcasecmp.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>str_split</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.strings.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>strcasecmp</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>