I'm try to calculate numbers inside string Example:
<?php
$str = '6 + 12 - ( 2 * 3 )';
$results = some_function($str);
Echo $results;
// outputs 12
?>
Can someone help me with this?
I'm try to calculate numbers inside string Example:
<?php
$str = '6 + 12 - ( 2 * 3 )';
$results = some_function($str);
Echo $results;
// outputs 12
?>
Can someone help me with this?
You can accomplish this via the eval function (it runs a string as if it were PHP).
<?php
function some_function($str) {
eval("return " . $str . ";");
}
$str = '6 + 12 - ( 2 * 3 )';
$results = some_function($str);
echo $results;
?>