I first thought of letting the customers write their formula in a textarea and then use eval() to execute it
That is highly error-prone and likely to lead to annoyed and frustrated users.
There are many approaches to this type of problem, but a Rules Engine seems particularly well suited. A Rules Engine allows you to specify this type of processing using meta data rather than hard-coding it. Some Rules Engines even provide end-user friendly user interfaces.
I have had good experience with Drools, though I have not looked at how it might integrate with PHP.
A Rules Engine is far more complex than just calling eval() on a user-supplied function, but it is far more likely to lead to maintainable software, and to happy customers.