1
0
mirror of https://github.com/php/doc-ja.git synced 2026-03-24 23:22:16 +01:00
Files
archived-doc-ja/reference/tokenizer/examples.xml
Satoru Yoshida a5f336342e sync en
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@346771 c90b9560-bf6c-de11-be94-00142212c4b1
2019-02-10 12:32:37 +00:00

70 lines
1.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 23fef04c872071ca5665fd75e8f4270ca960fb78 Maintainer: takagi Status: ready -->
<!-- CREDITS: hirokawa -->
<appendix xml:id="tokenizer.examples">
&reftitle.examples;
<para>
以下に tokenizer を用いた簡単な PHP スクリプトの例を示します。この例は、
PHP ファイルを読み込み、ソースから全てのコメントを削除し、コードのみを
出力するものです。
</para>
<example>
<title>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)) {
// 簡単な1文字毎のトークン
echo $token;
} else {
// トークン配列
list($id, $text) = $token;
switch ($id) {
case T_COMMENT:
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
-->