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="&gt;">(&gt;) - greater than</option>     <option value="&lt;">(&lt;) - less than</option>     <option value="&gt;=">(&gt;=) - greater or equal </option>     <option value="&lt;=">(&lt;=) - 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 '&lt;=':         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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -