Execute a validation inserted in a string

0

I have a PHP variable that assembles a logical string.

$str = "(('TR1'=='TR' OR 'TR2=='TR' OR 'TR'=='TR') AND ('10,0'=='10,1' OR '9,0'=='9,0'))";

I would like to find a way that validation is possible, type:

if ($ str) "One of the parameters on each side is valid";

Has anyone gone through this, or do you know a way to solve it?

    
asked by anonymous 12.09.2018 / 21:19

1 answer

2

To execute a String as a command in PHP, you can use the "eval ()" function.

<?php

eval('$var = (("TR1"=="TR" OR "TR2"=="TR" OR "TR"=="TR") AND ("10,0"=="10,1" OR "9,0"=="9,0"));');

echo $var;

?>

link

    
12.09.2018 / 22:46