PHP parse string as condition operator -
i have form user can create own condition. e.g
<select name="operator"> <option value="==">(==) equal</option> <option value="!=">(!=) - not equal</option> <option value=">">(>) - greater than</option> <option value="<">(<) - less than</option> <option value=">=">(>=) - greater or equal </option> <option value="<=">(<=) - less or equal </option> </select>
how parse operator string php interprets condition operator?
if($column $operator $value){ }
the long winded way of doing this:
switch($operator){ case '!=': if($column != $value){ } break; case '<=': case '<=': if($column <= $value){ } break; }
the way use eval
evaluates string php code.
using eval
not recommended security reasons. current approach using switch
best solution. other option using if
statements in similar manner.
Comments
Post a Comment