1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-24 15:52:13 +01:00
Files
archived-doc-ru/reference/tokenizer/examples.xml
Sergey Panteleev daef8df962 Обнуление тега Reviewed (#364)
[skip-lint]
[skip-spellcheck]
2021-11-16 13:03:53 +03:00

65 lines
1.7 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 23fef04c872071ca5665fd75e8f4270ca960fb78 Maintainer: aur Status: ready -->
<!-- Reviewed: no -->
<appendix xml:id="tokenizer.examples">
&reftitle.examples;
<para>
Простой пример PHP-скрипта, использующего tokenizer (лексер), который
читает PHP-файл, удаляет все комментарии из исходного кода
и выводит только чистый код.
</para>
<example>
<title>Удаление комментариев лексером</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)) {
// простая однабуквенная лексема
echo $token;
} else {
// массив с лексемой
list($id, $text) = $token;
switch ($id) {
case T_DOC_COMMENT:
// нет действий для комментариев
break;
default:
// все остальное -> выводим как есть
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
-->