From: "Enfors Christer" <[EMAIL PROTECTED]>

> Hi. I need a function that takes a mathematical expression
> in the form of a string, and calculates the result. PHP itself
> doesn't seem to provide one. I need something which can
> handle strings like:
>
>   10*73.2+3-(4*358.2874)/352

$str = "10*73.2+3-(4*358.2874)/352";
eval('$result = ' . $str . ';');
echo $result;

> ... and so on. If it handles functions (like cos(), pow(),
> exp()) too, then that would be great.

That will. Depending on what $str is coming from, make sure you're
validating it somewhat so there's not any malicious PHP code injected (for
example $str = 'file_get_contents("secretfile.txt")' )

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to