A user is allowed to enter any mathematical equation they like (with one variable):
x + 5
1 - x/2
(x/3) * (56/13)
eval()
Depends what you have to do but anyway, the cheapest way to doing it's using a replace function for the variables and then run the expression by using the eval().
Of course you need first to make sure that your formulas are in php syntax.
The good thing is that you can use any mathematical function supported by php, the bad thing is, it's never nice to use the eval() :)
PHPClasses
The other good option it's surfing the web until you find a parser :P
http://www.phpclasses.org/package/2695-PHP-Safely-evaluate-mathematical-expressions.html