I'm writing a script that will allow a user to input a string that is a math statement, to then be evaluated. I however have hit a roadblock. I cannot figure out how, using preg_match, to dissallow statements that have variables in them.
Using this, $calc = create_function("", "return (" . $string . ");" ); $calc();
, allows users to input a string that will be evaluated, but it crashes whenever something like echo 'foo';
is put in place of the variable $string
.
I've seen this post, but it does not allow for math functions inside the string, such as $string = 'sin(45)';
.