My standard answer to this question whenever it crops up:
Don't use eval (especially as you're stating that this is user input) or reinvent the wheel by writing your own formula parser.
Take a look at the evalMath class on PHPClasses. It should do everything that you're asking, in a safe sandbox.