Re: Evaluating math without eval()

From: Date: Thu, 10 Apr 2008 12:15:57 +0000
Subject: Re: Evaluating math without eval()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-272829@lists.php.net to get a copy of this message
First post to this list! I'm trying to figure out how to evaluate a string with a mathematical expression and get a result, but without using eval() as I'm accepting user input into the string. I don't just want addition, subtraction, multiplication and division - I'd like to take advantage of other functions like ceil, floor etc. So the string "18-10" should give me 8, "ceil(1/2)*10" should be 10 (if my maths is correct) and the string "18-10;\r\nunlink('/var/www/*');" should not execute.
If you can provide your users with distinct inputs (if it's a form) go that route. -- Richard Heyes Employ me: http://www.phpguru.org/cv

« previous php.general (#272829) next »