Re: How to convert a string into a mathematical expression?

From: Date: Fri, 13 Jul 2001 09:47:29 +0000
Subject: Re: How to convert a string into a mathematical expression?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-59947@lists.php.net to get a copy of this message
But *very* dangerous! :) If the user passed malicious code in the string, all heck could break loose. You will need to ensure that user input is filtered before being passed to eval. Also, the Dev list is for discussing development of the PHP language, not development with - this discussion would be better placed on the PHP General mailing list. --zak Derick wrote: > On Fri, 13 Jul 2001, Christodoulou Demetris wrote: > > > Hi list. > > I have strings that are mathematical expressions. These strings are > > submitted through forms. > > For example a string might be $a="1+cos(0.3)*x". > > Is there a way to convert this string to a mathematical expression that can > > be calculated? > > This is possible: > > <?php > $x = 2; > $a = '$c = 1 + cos (0.3) * $x;'; > eval ($a); > echo $c; > ?> > > outputs: > 2.9106729782512 > > regards, > Derick

« previous php.dev (#59947) next »