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
slightly risky possibility if you were running your code on a linux box is to use the bc command (making sure to escape your inputs properly before giving it to the system cmd). i can't say using system is much better than the risks of eval, so I am expecting some downvotes here.