I have this string ($query) returning from preg_replace
'SELECT ({$array["sum"]}/ 5)'
how can i evaluate it, so that the result would be 'SELECT (100/5)' for example !
I tried
eval($query)
But with no success!
Do you have a better idea ?
you're not using eval right:
$evaluated = eval("return $query;");
take care you do not have any syntax errors. also you just might do it wrong when you build SQL queries this way. Just saying, I hope you're old enough.
"SELECT ({total_price.total_id}/ 5)" output: "SELECT (".mysqli_real_escape_string($this->app_array["application"]["sql"]["total_price"]["total_id"])."/ 5)"Just glue them together with the . operator:
$array['sum'] = 100;
echo 'SELECT (' . $array['sum' ] . ' / 5)';
will result in:
SELECT (100 / 5)