3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = '(2 * 10 + 5) Euro and (10 + 2) cents'; $regex = '#\((([^()]+|(?R))*)\)#'; if (preg_match_all($regex, $string ,$matches)) { $eqs = $matches[1]; foreach($eqs as $frm) { $frm_eval = eval("return $frm;"); $string = str_replace('(' . $frm . ')', $frm_eval, $string); } echo $string; } else { //no parenthesis echo $string; }
based on RR31F
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
25 Euro and 12 cents