<?php
$input = '(800 + 20) - 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;
if(in_array($id, array(T_DNUMBER, T_LNUMBER)))
$expr .= $text;
}
$result = eval("return ({$expr});");
print "\n" . $expr;
print "\n" . $result;
preferences:
55.84 ms | 402 KiB | 5 Q