Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 703d980c580707c382b4e43e25965bc5 > files > 12103

php-manual-pt_BR-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
>Funções de Tokenizer</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Manual do PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Referência das Funções"
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"
>Manual do PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.tidynode-getparent.html"
ACCESSKEY="P"
>Anterior</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"
>Próxima</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. Funções de Tokenizer</H1
><DIV
CLASS="PARTINTRO"
><A
NAME="AEN228629"
></A
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tokenizer.intro"
>Introdução</A
></H1
><P
>&#13;     As funções de tokenizer formam uma interface para o
     tokenizer do PHP imbutido no Engine Zend. Usando essas
     funções você pode escrever ferramentas próprias para
     análise e modificação de código PHP sem ter que lidar com a
     especificação da linguagem em um nível léxico.
    </P
><P
>&#13;     Veja também o <A
HREF="tokens.html"
>apêndice sobre tokens</A
>.
    </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tokenizer.requirements"
>Dependências</A
></H1
><P
>Nenhuma biblioteca externa é necessária para compilar esta extensão.</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tokenizer.installation"
>Instalação</A
></H1
><P
>&#13;  Começando no PHP 4.3.0, essas funções estão habilitadas a menos que seja dito o contrário.
  Para versões anteriores, você tem que configurar e compilar o PHP com
  <CODE
CLASS="option"
>--enable-tokenizer</CODE
>. Você pode desabilitar
  suporte à extensão tokenizer com <CODE
CLASS="option"
>--disable-tokenizer</CODE
>.
 </P
><P
>A versão para Windows do <TT
CLASS="literal"
>PHP</TT
>
 tem suporte embutido para esta extensão. Você não precisa carregar nenhuma extensão
 adicional para utilizar essas funções.</P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
   Suporte integrado para tokenizer está disponível a partir do PHP 4.3.0.
  </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tokenizer.constants"
>Constantes pré-definidas</A
></H1
><P
>&#13;  Quando a extensão for ou compilado no PHP ou carregada dinamicamente em tempo
  de execução, os tokens listados em <A
HREF="tokens.html"
>Apêndice R</A
> são definidos como
  constantes.
 </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="tokenizer.examples"
>Exemplos</A
></H1
><P
>&#13;     Aqui está um exemplo simples de scripts PHP usando o tokenizer que
     lerá um arquivo PHP, retirará todos os comentários do fonte e
     imprimirá apenas o código puro.
    </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN228654"
></A
><P
><B
>Exemplo 1. Retira os comentários com o 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 não existe no PHP 5.<br /> * As três linhas seguintes definem ela para<br /> * preservar compatibilidade com versões anteriores.<br /> *<br /> * As duas linhas seguintes definem T_DOC_COMMENT que existe apenas no PHP 5,<br /> * que nós chamaremos como T_ML_COMMENT para o 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">// token simples de 1 caracter<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">// array de tokens<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">// Nós definimos essa<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">// e essa<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// não faz nada com os comentários<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">// Qualquer outra coisa, imprime como é<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
>Índice</B
></DT
><DT
><A
HREF="function.token-get-all.html"
>token_get_all</A
>&nbsp;--&nbsp;Divide um dado fonte em tokens do PHP</DT
><DT
><A
HREF="function.token-name.html"
>token_name</A
>&nbsp;--&nbsp;Pega o nome simbólico de um dado token do PHP</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"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Principal</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.token-get-all.html"
ACCESSKEY="N"
>Próxima</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"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>token_get_all</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>