Re: Turning a string into a condition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2012-02-16 at 15:38 -0500, Marc Guay wrote:

> > It sounds like you have a string "$x < $y" in the database that you then
> > replace into a string "4 < 5" which you want to test a conditional on. If
> > this is the case, why are you storing conditionals in the database?
> 
> The user will be able to construct their own query strings, it's
> complicated but necessary.  The issue I'm dealing with, though, is
> this:
> 
> $condition = "4 < 5";
> if ($condition){
> //do stuff
> }
> 


You were on the right lines with the eval:

$condition = "return 4 < 5;";

if (eval($condition))
{
    //do stuff
}

I just added the return statement and the semicolon, because the error
was complaining about it not being a proper PHP statement basically.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux