PHP preg_match Math Function

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-05-26T21:08:44Z Indexed on 2010/05/26 21:11 UTC
Read the original article Hit count: 158

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about regex