The tokenizer functions provide an interface to the
PHP tokenizer embedded in the Zend Engine. Using these
functions you may write your own PHP source analyzing
or modification tools without having to deal with the
language specification at the lexical level.
See also the appendix about tokens.
Tyto funkce jsou k dispozici jako sou��st
standardn�ho modulu, kter� je v�dy dostupn�.
Beginning with PHP 4.3.0 these functions are enabled by default.
For older versions you have to configure and compile PHP with
--enable-tokenizer. You can disable
tokenizer support with --disable-tokenizer.
Verze PHP pro Windows
m� vestav�nou podporu pro toto roz���en�. K pou�it� t�chto funkc� nen� t�eba
na��tat ��dn� dal�� roz���en�.
Pozn�mka:
Builtin support for tokenizer is available with PHP 4.3.0.
Tyto konstanty jsou definov�ny t�mto roz���en�m a budou k dispozici pouze
tehdy, bylo-li roz���en� zkompilov�no spole�n� s PHP nebo dynamicky zavedeno
za b�hu.
Here is a simple example PHP scripts using the tokenizer that
will read in a PHP file, strip all comments from the source
and print the pure code only.
P��klad 1. Strip comments with the tokenizer
<?php
$source = file_get_contents("somefile.php");
$tokens = token_get_all($source);
if (!defined('T_ML_COMMENT')) {
define('T_ML_COMMENT', T_COMMENT);
} else {
define('T_DOC_COMMENT', T_ML_COMMENT);
}
foreach ($tokens as $token) {
if (is_string($token)) {
echo $token;
} else {
list($id, $text) = $token;
switch ($id) {
case T_COMMENT:
case T_ML_COMMENT: case T_DOC_COMMENT: break;
default:
echo $text;
break;
}
}
}
?>
|
|