Formula = $ " ((total mass / 1000) + production costs + selling expenses + administrative expenses + profit amount) * * cost coefficient area coefficient " // formula // number $ Total = 10 ; // total $ production_cost = 1 ; // production costs $ sales_cost = 2 ; // cost of sales $ management_cost = 3 ; // administrative expenses $ profit = 4 ; // profit amount $ costfactor = 5 ; // cost coefficient $ replace = array ($ total, $ production_cost, sales_cost $, $ management_cost, Profit $, $ costfactor, ' . 1 '); $ Formula = str_replace ($ Find, Replace $, $ Formula); // replace string print_r ($ Formula); Die; // Price $ = unitPrice, the eval ( " return $ Formula " ); // string PHP code is calculated as