Sophie

Sophie

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

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
>Tokenizer Functions</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="函数参考"
HREF="funcref.html"><LINK
REL="PREVIOUS"
TITLE="tidyNode::getParent"
HREF="function.tidynode-getparent.html"><LINK
REL="NEXT"
TITLE="token_get_all"
HREF="function.token-get-all.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="reference"
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.tidynode-getparent.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.token-get-all.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="reference"
><A
NAME="ref.tokenizer"
></A
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="title"
>CLXVII. Tokenizer Functions</H1
><DIV
CLASS="PARTINTRO"
><A
NAME="AEN235301"
></A
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tokenizer.intro"
>简介</A
></H1
><P
>&#13;     The tokenizer functions provide an interface to the
     PHP tokenizer embedded in the Zend Engine. Using these
     functions you may write your own PHP source analyzing
     or modification tools without having to deal with the
     language specification at the lexical level.
    </P
><P
>&#13;     See also the <A
HREF="tokens.html"
>appendix about tokens</A
>.
    </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tokenizer.requirements"
>需求</A
></H1
><P
>要编译本扩展模块无需外部库文件。</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tokenizer.installation"
>安装</A
></H1
><P
>&#13;  Beginning with PHP 4.3.0 these functions are enabled by default.
  For older versions you have to configure and compile PHP with
  <CODE
CLASS="option"
>--enable-tokenizer</CODE
>. You can disable
  tokenizer support with <CODE
CLASS="option"
>--disable-tokenizer</CODE
>.
 </P
><P
> <TT
CLASS="literal"
>PHP</TT
> 的 Windows
版本已经内置该扩展模块的支持。无需加载任何附加扩展库即可使用这些函数。</P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
   Built-in support for tokenizer is available as of PHP 4.3.0.
  </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tokenizer.constants"
>预定义常量</A
></H1
><P
>&#13;  When the extension has either been compiled into PHP or dynamically loaded
  at runtime, the tokens listed in <A
HREF="tokens.html"
>附录 R</A
> are defined as
  constants.
 </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tokenizer.examples"
>范例</A
></H1
><P
>&#13;     Here is a simple example PHP scripts using the tokenizer that 
     will read in a PHP file, strip all comments from the source
     and print the pure code only.
    </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN235326"
></A
><P
><B
>例 1. Strip comments with the tokenizer</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">/*<br /> * T_ML_COMMENT does not exist in PHP 5.<br /> * The following three lines define it in order to<br /> * preserve backwards compatibility.<br /> *<br /> * The next two lines define the PHP 5 only T_DOC_COMMENT,<br /> * which we will mask as T_ML_COMMENT for PHP 4.<br /> */<br /></font><font color="#007700">if (!</font><font color="#0000BB">defined</font><font color="#007700">(</font><font color="#DD0000">'T_ML_COMMENT'</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">define</font><font color="#007700">(</font><font color="#DD0000">'T_ML_COMMENT'</font><font color="#007700">, </font><font color="#0000BB">T_COMMENT</font><font color="#007700">);<br />} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">define</font><font color="#007700">(</font><font color="#DD0000">'T_DOC_COMMENT'</font><font color="#007700">, </font><font color="#0000BB">T_ML_COMMENT</font><font color="#007700">);<br />}<br /><br /></font><font color="#0000BB">$source </font><font color="#007700">= </font><font color="#0000BB">file_get_contents</font><font color="#007700">(</font><font color="#DD0000">'example.php'</font><font color="#007700">);<br /></font><font color="#0000BB">$tokens </font><font color="#007700">= </font><font color="#0000BB">token_get_all</font><font color="#007700">(</font><font color="#0000BB">$source</font><font color="#007700">);<br /><br />foreach (</font><font color="#0000BB">$tokens </font><font color="#007700">as </font><font color="#0000BB">$token</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;if (</font><font color="#0000BB">is_string</font><font color="#007700">(</font><font color="#0000BB">$token</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// simple 1-character token<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">echo </font><font color="#0000BB">$token</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// token array<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">list(</font><font color="#0000BB">$id</font><font color="#007700">, </font><font color="#0000BB">$text</font><font color="#007700">) = </font><font color="#0000BB">$token</font><font color="#007700">;<br /> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch (</font><font color="#0000BB">$id</font><font color="#007700">) { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case </font><font color="#0000BB">T_COMMENT</font><font color="#007700">: <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case </font><font color="#0000BB">T_ML_COMMENT</font><font color="#007700">: </font><font color="#FF8000">// we've defined this<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">case </font><font color="#0000BB">T_DOC_COMMENT</font><font color="#007700">: </font><font color="#FF8000">// and this<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// no action on comments<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">break;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// anything else -&gt; output "as is"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">echo </font><font color="#0000BB">$text</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>目录</B
></DT
><DT
><A
HREF="function.token-get-all.html"
>token_get_all</A
>&nbsp;--&nbsp;Split given source into PHP tokens</DT
><DT
><A
HREF="function.token-name.html"
>token_name</A
>&nbsp;--&nbsp;Get the symbolic name of a given PHP token</DT
></DL
></DIV
></DIV
></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.tidynode-getparent.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.token-get-all.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>tidyNode::getParent</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="funcref.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>token_get_all</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>