Hi,
I am a PHP coder, recently ran into a bit of a problem trying to evaluate expressions in PHP.
I have an expression which is stored in a string variable and when I try to evaluate it, it always returns a 'TRUE'
Eg:
[PHP]
$str = '6.0 >= 8.5' ;
if($str)
{
//do something
}
else
{
//do something else
}[/PHP]
The value(rather the expression) inside 'str' variable comes from the database and I am suppossed to check whether it returns a 'TRUE' or a 'FALSE', but it always evaluates to 'TRUE'..
I also tried doing something like foll., still doesn't work, always returns 'TRUE'
[PHP]$a = 6.0 ;
$b = '>=' ;
$c = 8.5 ;
if( (boolean) $a .$b .$c)
{
//do something
}
else
{
//do something else
}[/PHP]
The code is always treating the expression as a string and evaluating to 'TRUE', can anyone help me with a way of making the string work as an expression..
Many thanks,
Sib
I am a PHP coder, recently ran into a bit of a problem trying to evaluate expressions in PHP.
I have an expression which is stored in a string variable and when I try to evaluate it, it always returns a 'TRUE'
Eg:
[PHP]
$str = '6.0 >= 8.5' ;
if($str)
{
//do something
}
else
{
//do something else
}[/PHP]
The value(rather the expression) inside 'str' variable comes from the database and I am suppossed to check whether it returns a 'TRUE' or a 'FALSE', but it always evaluates to 'TRUE'..
I also tried doing something like foll., still doesn't work, always returns 'TRUE'
[PHP]$a = 6.0 ;
$b = '>=' ;
$c = 8.5 ;
if( (boolean) $a .$b .$c)
{
//do something
}
else
{
//do something else
}[/PHP]
The code is always treating the expression as a string and evaluating to 'TRUE', can anyone help me with a way of making the string work as an expression..
Many thanks,
Sib
Comment