3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input = '$x=100; ((800 + 20) - 800 / 2)'; $tokens = token_get_all("<?php {$input}"); $expr = ''; foreach($tokens as $token){ if(in_array($token, array(T_DNUMBER, T_LNUMBER, T_BOOLEAN_AND, T_BOOLEAN_OR, T_DEC, T_DIV_EQUAL,T_DOUBLE_CAST,T_ELSE,T_ELSEIF, T_ENDIF,T_IF,T_INC, T_IS_EQUAL, T_IS_GREATER_OR_EQUAL,T_IS_IDENTICAL,T_IS_NOT_EQUAL, T_IS_NOT_IDENTICAL, T_IS_SMALLER_OR_EQUAL, T_LOGICAL_AND , T_LOGICAL_OR ,T_MINUS_EQUAL,T_MOD_EQUAL, T_MUL_EQUAL, T_OR_EQUAL, T_PLUS_EQUAL, T_POW, T_POW_EQUAL , T_STRING_VARNAME,T_VARIABLE , T_XOR_EQUAL ))) echo $token; if(is_string($token)){ if(in_array($token, array('(', ')', '+', '-', '/', '*','if','IF' , '{' ,'}' , ';' ,'$'), true)) $expr .= $token; continue; } list($id, $text) = $token; if(in_array($id, array(T_DNUMBER, T_LNUMBER))) $expr .= $text; } eval("\$result = {$expr};"); print "\nexpr = " . $expr; print "\nres = " . $result;
based on L3sf8
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0rc2
expr = 100;((800+20)-800/2) res = 100