mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 07:22:16 +01:00
70 lines
1.6 KiB
XML
70 lines
1.6 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 23fef04c872071ca5665fd75e8f4270ca960fb78 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
|
|
|
|
$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_DOC_COMMENT:
|
|
// 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
|
|
-->
|
|
|