For example: $condition = "2 = = 2 && 3 = = 5";
if ($condition) {
Echo 1;
}
How do I convert a $condition to an if-recognizable condition? This judgment is treated as a string constant with a value of true
Reply to discussion (solution)
if (eval ("Return $condition;")) {
$condition = "2<=2 && 2>=1 && (SNB = = = SNB | | SNB = = = Hfu) "; if (eval (" Return $condition; ")) {echo 1;} else {echo 2;}
Eval () can solve the case of pure numbers, the string has an English letter will be error, if it is above the situation what to do?
2<=2 && 2>=1 && (SNB = = SNB | | snb = = = Hfu)
itself is not a valid PHP conditional expression, do not say Eval, is that you write directly in if is to error.
$condition = "2<=2 && 2>=1 && (SNB = = = SNB | | SNB = = = Hfu) "; if (eval (" Return $condition; ")) {echo 1;} else {echo 2;} if (2<=2 && 2>=1 && (' snb ' = = = ' SNB ' | | ' SNB ' = = = ' Hfu ') {echo 3;}
Well, the first paragraph of the $condition and the second paragraph if the content is equivalent it is just a string, one is the normal if condition.
There's no problem with running the second paragraph.
The first call to Eval () will report a constant undefined error, which should be escaped here?
$condition = "2<=2 && 2>=1 && (SNB = = = SNB | | SNB = = = Hfu) "; if (eval (" Return $condition; ")) {echo 1;} else {echo 2;} if (2<=2 && 2>=1 && (' snb ' = = = ' SNB ' | | ' SNB ' = = = ' Hfu ') {echo 3;}
Well, the first paragraph of the $condition and the second paragraph if the content is equivalent it is just a string, one is the normal if condition.
There's no problem with running the second paragraph.
The first call to Eval () will report a constant undefined error, which should be escaped here?
Your intention is (' SNB ' = = = ' SNB ' | | ' SNB ' = = = ' Hfu ') but you write (SNB = = = SNB | | snb = = = Hfu) A variable that does not even have a $ symbol, is naturally understood as constant, yet you do not define a constant.
Convert them with variables, otherwise SNB and HFU will be interpreted as constants.
$SNB = "SNB"; $hfu = "Hfu"; $condition = ' 2<=2 && 2>=1 && ($snb = = = $SNB | | $snb = = = $hfu) '; if (eval ("Return $condition;")) { echo 1; } else { echo 2; }
Uh, it's settled, thank you, big God.
Uh, it's settled, thank you, big God.
That's a knot.