<?
$a=1;
$flag = 0;
$test = "(a==1) OR (b==1)";
$string = "if($test){ $flag =1;}";
var_dump($string);
eval($string);
if( $flag ==1 ) {var_dump($a);}
?>
Produces:
string(28) "if((a==1) OR (b==1)){ 0 =1;}"
Parse error: parse error in c:/apache/htdocs/test2.php(7) : eval()'d code on
line 1

Why?
Because of using "" instead of '', or if use "" the escape the $
Also there is another problem:
$test = "(a==1) OR (b==1)";
must be
$test = "(\$a==1) OR (\$b==1)";
if  it was
$test = "($a==1) OR ($b==1)";
then there will be a substitution. As a side effect this will work because
if $a=1
then $test="(1==1) or (what_is_b==1)
which given to eval() will work.


Andrey Hristov
IcyGEN Corporation
http://www.icygen.com
99%

----- Original Message -----
From: "Rick Emery" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, August 23, 2001 8:27 PM
Subject: RE: [PHP-DB] variable if statement


> eval will work, but the entire thing must be in the eval().  It would look
> like:
>
> $flag = 0;
> $test = "(a==1) OR (b==1)";
> $string = "if($test){ $flag =1;}";
> eval($string);
> if( $flag ==1 ) {do_something;}
>
> I had to resort to this in a similar situation.  I read the condition and
> result action in a MySQL database.
>
> Richard Emery
> Excel Communications, Inc.
> IT Sr. Project Manager
> (972) 478-3398
> (972) 944-0542 (pager)
>
> There is no "trying"...
> There is only "Do" or "Not Do"
>
>
>
> -----Original Message-----
> From: Brian Weisenthal [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 23, 2001 12:15 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] variable if statement
>
>
> i want to do something like this:
>
> $string="($a==1) OR ($b==2)";
>
> if ($string) { do something ; }
>
> any ideas? i tried using if (eval($string)) but that just gave me errors.
>
> thanks
>
>
>
>
> --
> PHP Database 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]
>
> --
> PHP Database 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]
>
>


-- 
PHP Database 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]

Reply via email to