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
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]