3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * T_ML_COMMENT n'existe pas en PHP 5. * Les lignes suivantes le définisse afin de rendre * compatible notre code. * * Ensuite, les 2 lignes définissent T_DOC_COMMENT uniquement pour PHP 5, * que nous masquons en T_ML_COMMENT pour PHP 4. */ if (!defined('T_ML_COMMENT')) { define('T_ML_COMMENT', T_COMMENT); } else { define('T_DOC_COMMENT', T_ML_COMMENT); } $source = file_get_contents('example.php'); $tokens = token_get_all($source); foreach ($tokens as $token) { if (is_string($token)) { // un simple caractère token echo $token; } else { // tableau token list($id, $text) = $token; switch ($id) { case T_COMMENT: case T_ML_COMMENT: // nous avons défini ceci case T_DOC_COMMENT: // et ceci // Aucune action sur les commentaires break; default: // rien d'autre -> affiche "as is" echo $text; break; } } } ?>
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Warning: file_get_contents(): open_basedir restriction in effect. File(example.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/jXv1T on line 16 Warning: file_get_contents(example.php): Failed to open stream: Operation not permitted in /in/jXv1T on line 16
Output for 8.0.13
Warning: file_get_contents(example.php): Failed to open stream: No such file or directory in /in/jXv1T on line 16
Output for 5.3.7 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0, 7.3.32 - 7.3.33, 7.4.33
Warning: file_get_contents(example.php): failed to open stream: No such file or directory in /in/jXv1T on line 16
Output for 7.2.29 - 7.2.33, 7.3.12 - 7.3.31, 7.4.0 - 7.4.32
Warning: file_get_contents(): open_basedir restriction in effect. File(example.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/jXv1T on line 16 Warning: file_get_contents(example.php): failed to open stream: Operation not permitted in /in/jXv1T on line 16

preferences:
203.38 ms | 402 KiB | 253 Q