mirror of
https://github.com/php/doc-es.git
synced 2026-03-26 08:22:08 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@306864 c90b9560-bf6c-de11-be94-00142212c4b1
84 lines
2.0 KiB
XML
84 lines
2.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 96c9d88bad9a7d7d44bfb7f26c226df7ee9ddf26 Maintainer: marcogrossisas Status: ready -->
|
|
|
|
<appendix xml:id="tokenizer.examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
Aquí hay un simple ejemplo de scripts PHP donde se usa el tokenizer
|
|
para leer en un archivo PHP, quitar todo los comentarios del archivo
|
|
original y mostrar solamente el código puro.
|
|
</para>
|
|
<example>
|
|
<title>Quitar comentarios con el tokenizer</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/*
|
|
* T_ML_COMMENT no existe en PHP 5.
|
|
* Las siguientes tres líneas lo definen para
|
|
* preservar compatibilidades anteriores.
|
|
*
|
|
* Las siguientes dos líneas definen el T_DOC_COMMENT de PHP 5,
|
|
* el cual será sobreescrito como T_ML_COMMENT para PHP 4.
|
|
*/
|
|
if (!defined('T_ML_COMMENT')) {
|
|
define('T_ML_COMMENT', T_COMMENT);
|
|
} else {
|
|
define('T_DOC_COMMENT', T_ML_COMMENT);
|
|
}
|
|
|
|
$source = file_get_contents('example.php');
|
|
$tokens = token_get_all($source);
|
|
|
|
foreach ($tokens as $token) {
|
|
if (is_string($token)) {
|
|
// simple 1-character token
|
|
echo $token;
|
|
} else {
|
|
// token array
|
|
list($id, $text) = $token;
|
|
|
|
switch ($id) {
|
|
case T_COMMENT:
|
|
case T_ML_COMMENT: // hemos definido esto
|
|
case T_DOC_COMMENT: // y esto
|
|
// ninguna acción en comentarios
|
|
break;
|
|
|
|
default:
|
|
// cualquier otra cosa -> salida "tal cual"
|
|
echo $text;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</appendix>
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|
|
|