0

I need to convert the formula like string to its calculated value, in PHP.

For eg:

$str = "(20000+(2000*(40/100)))*(10/100)";
$calculated_value = ????; // Calculated value of the above string "$str".

I need to calculate value of the string "$str" and store it in separate string. Please help me out.

Thanks in advance.

2
  • If someone suggests using a function starting with an e and ending on al, then ignore that. You need to parse this string (possibly using a stack-based approach). Fun! Commented Mar 14, 2013 at 9:29
  • Take a look at @ircmaxell's answer to this previous version of your question: stackoverflow.com/questions/12692727/… - it's the best PHP answer you'll find Commented Mar 14, 2013 at 9:38

1 Answer 1

1

Take a look on this: http://www.phpclasses.org/package/2695-PHP-Safely-evaluate-mathematical-expressions.html

And Process mathematical equations in php

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.