3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $input = '((800 + {$test->value}) - 800 / 2)'; $tokens = token_get_all("<?php {$input}"); $expr = ''; foreach($tokens as $token){ if(is_string($token)){ if(in_array($token, array('(', ')', '+', '-', '/', '*', '{', '$', '>', '}'), true)) $expr .= $token; continue; } list($id, $text) = $token; var_dump($token); if(in_array($id, array(T_DNUMBER, T_LNUMBER))) $expr .= $text; } //eval("\$result = {$expr};"); print "\nexpr = " . $expr; //print "\nres = " . $result;
Output for 7.0.0 - 7.1.0
array(3) { [0]=> int(379) [1]=> string(6) "<?php " [2]=> int(1) } array(3) { [0]=> int(317) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(382) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(382) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(320) [1]=> string(5) "$test" [2]=> int(1) } array(3) { [0]=> int(366) [1]=> string(2) "->" [2]=> int(1) } array(3) { [0]=> int(319) [1]=> string(5) "value" [2]=> int(1) } array(3) { [0]=> int(382) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(382) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(317) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(382) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(382) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(317) [1]=> string(1) "2" [2]=> int(1) } expr = ((800+{})-800/2)
Output for 5.6.8 - 5.6.28
array(3) { [0]=> int(376) [1]=> string(6) "<?php " [2]=> int(1) } array(3) { [0]=> int(308) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(379) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(379) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(312) [1]=> string(5) "$test" [2]=> int(1) } array(3) { [0]=> int(363) [1]=> string(2) "->" [2]=> int(1) } array(3) { [0]=> int(310) [1]=> string(5) "value" [2]=> int(1) } array(3) { [0]=> int(379) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(379) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(308) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(379) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(379) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(308) [1]=> string(1) "2" [2]=> int(1) } expr = ((800+{})-800/2)
Output for 5.5.24 - 5.5.35
array(3) { [0]=> int(374) [1]=> string(6) "<?php " [2]=> int(1) } array(3) { [0]=> int(306) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(377) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(377) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(310) [1]=> string(5) "$test" [2]=> int(1) } array(3) { [0]=> int(361) [1]=> string(2) "->" [2]=> int(1) } array(3) { [0]=> int(308) [1]=> string(5) "value" [2]=> int(1) } array(3) { [0]=> int(377) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(377) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(306) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(377) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(377) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(306) [1]=> string(1) "2" [2]=> int(1) } expr = ((800+{})-800/2)
Output for 5.4.0 - 5.4.45
array(3) { [0]=> int(372) [1]=> string(6) "<?php " [2]=> int(1) } array(3) { [0]=> int(305) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(375) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(375) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(309) [1]=> string(5) "$test" [2]=> int(1) } array(3) { [0]=> int(359) [1]=> string(2) "->" [2]=> int(1) } array(3) { [0]=> int(307) [1]=> string(5) "value" [2]=> int(1) } array(3) { [0]=> int(375) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(375) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(305) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(375) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(375) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(305) [1]=> string(1) "2" [2]=> int(1) } expr = ((800+{})-800/2)
Output for 5.3.0 - 5.3.29
array(3) { [0]=> int(368) [1]=> string(6) "<?php " [2]=> int(1) } array(3) { [0]=> int(305) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(371) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(371) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(309) [1]=> string(5) "$test" [2]=> int(1) } array(3) { [0]=> int(357) [1]=> string(2) "->" [2]=> int(1) } array(3) { [0]=> int(307) [1]=> string(5) "value" [2]=> int(1) } array(3) { [0]=> int(371) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(371) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(305) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(371) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(371) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(305) [1]=> string(1) "2" [2]=> int(1) } expr = ((800+{})-800/2)
Output for 5.2.2 - 5.2.17
array(3) { [0]=> int(367) [1]=> string(6) "<?php " [2]=> int(1) } array(3) { [0]=> int(305) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(370) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(370) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(309) [1]=> string(5) "$test" [2]=> int(1) } array(3) { [0]=> int(356) [1]=> string(2) "->" [2]=> int(1) } array(3) { [0]=> int(307) [1]=> string(5) "value" [2]=> int(1) } array(3) { [0]=> int(370) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(370) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(305) [1]=> string(3) "800" [2]=> int(1) } array(3) { [0]=> int(370) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(370) [1]=> string(1) " " [2]=> int(1) } array(3) { [0]=> int(305) [1]=> string(1) "2" [2]=> int(1) } expr = ((800+{})-800/2)
Output for 5.1.1 - 5.2.1
array(2) { [0]=> int(367) [1]=> string(6) "<?php " } array(2) { [0]=> int(305) [1]=> string(3) "800" } array(2) { [0]=> int(370) [1]=> string(1) " " } array(2) { [0]=> int(370) [1]=> string(1) " " } array(2) { [0]=> int(309) [1]=> string(5) "$test" } array(2) { [0]=> int(356) [1]=> string(2) "->" } array(2) { [0]=> int(307) [1]=> string(5) "value" } array(2) { [0]=> int(370) [1]=> string(1) " " } array(2) { [0]=> int(370) [1]=> string(1) " " } array(2) { [0]=> int(305) [1]=> string(3) "800" } array(2) { [0]=> int(370) [1]=> string(1) " " } array(2) { [0]=> int(370) [1]=> string(1) " " } array(2) { [0]=> int(305) [1]=> string(1) "2" } expr = ((800+{})-800/2)
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/v8khv on line 28
Process exited with code 255.
Output for 5.0.0 - 5.0.5
array(2) { [0]=> int(365) [1]=> string(6) "<?php " } array(2) { [0]=> int(304) [1]=> string(3) "800" } array(2) { [0]=> int(368) [1]=> string(1) " " } array(2) { [0]=> int(368) [1]=> string(1) " " } array(2) { [0]=> int(308) [1]=> string(5) "$test" } array(2) { [0]=> int(354) [1]=> string(2) "->" } array(2) { [0]=> int(306) [1]=> string(5) "value" } array(2) { [0]=> int(368) [1]=> string(1) " " } array(2) { [0]=> int(368) [1]=> string(1) " " } array(2) { [0]=> int(304) [1]=> string(3) "800" } array(2) { [0]=> int(368) [1]=> string(1) " " } array(2) { [0]=> int(368) [1]=> string(1) " " } array(2) { [0]=> int(304) [1]=> string(1) "2" } expr = ((800+{})-800/2)
Output for 4.4.2 - 4.4.9
array(2) { [0]=> int(354) [1]=> string(6) "<?php " } array(2) { [0]=> int(303) [1]=> string(3) "800" } array(2) { [0]=> int(357) [1]=> string(1) " " } array(2) { [0]=> int(357) [1]=> string(1) " " } array(2) { [0]=> int(307) [1]=> string(5) "$test" } array(2) { [0]=> int(344) [1]=> string(2) "->" } array(2) { [0]=> int(305) [1]=> string(5) "value" } array(2) { [0]=> int(357) [1]=> string(1) " " } array(2) { [0]=> int(357) [1]=> string(1) " " } array(2) { [0]=> int(303) [1]=> string(3) "800" } array(2) { [0]=> int(357) [1]=> string(1) " " } array(2) { [0]=> int(357) [1]=> string(1) " " } array(2) { [0]=> int(303) [1]=> string(1) "2" } expr = ((800+{})-800/2)
Output for 4.3.0 - 4.4.1
array(2) { [0]=> int(353) [1]=> string(6) "<?php " } array(2) { [0]=> int(302) [1]=> string(3) "800" } array(2) { [0]=> int(356) [1]=> string(1) " " } array(2) { [0]=> int(356) [1]=> string(1) " " } array(2) { [0]=> int(306) [1]=> string(5) "$test" } array(2) { [0]=> int(343) [1]=> string(2) "->" } array(2) { [0]=> int(304) [1]=> string(5) "value" } array(2) { [0]=> int(356) [1]=> string(1) " " } array(2) { [0]=> int(356) [1]=> string(1) " " } array(2) { [0]=> int(302) [1]=> string(3) "800" } array(2) { [0]=> int(356) [1]=> string(1) " " } array(2) { [0]=> int(356) [1]=> string(1) " " } array(2) { [0]=> int(302) [1]=> string(1) "2" } expr = ((800+{})-800/2)