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

From: Date: Fri, 13 Jul 2001 09:17:15 +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-59944@lists.php.net to get a copy of this message
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 --------------------------------------------------------------------- PHP: Scripting the Web - www.php.net - derick@php.net SRM: Site Resource Manager - www.vl-srm.net ---------------------------------------------------------------------

« previous php.dev (#59944) next »