Formula calculation mechanism for web

arashjaf

New Member
There is a group of simple formulas for calculating some values.I need to implement this for the web interface (I make this in PHP).To store formulas I am using simple format like this: "X1+X2+X3". When I need to make calculations, I call function preg_replace in the loop for replacing X1, X2 .. by real data (entered by user or saved earlier - it is not important)Then I use function eval('$calculation_result ='. $trans_formula .';') where $trans_formula stores text of the formula with substituted data.This mechanism looks like a primitive and I have a feeling that I'm trying to re-invent the wheel. Perhaps there are some ready algorithms, techniques, methods to accomplish this? Not necessary PHP code. I
 
Back
Top