PHP 8.6.0 Beta 1 is available for testing

Ejemplos

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.

Ejemplo #1 Quitar comentarios con el tokenizer

<?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;
 }
 }
}
?>

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes

There are no user contributed notes for this page.

AltStyle によって変換されたページ (->オリジナル) /