note 71045 deleted from function.eval by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 19:55:09 +0000 |
| Subject: | note 71045 deleted from function.eval by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155292@lists.php.net to get a copy of this message | ||
Note Submitter: Slimshady451
----
A simple function to eval sum user's code for maths.
<?php
function strtonum($str)
{
$str =
preg_replace('
([^+\-*=/\(\)\d\^<>&|\.]*)','',$str);
if(empty($str))$str = '0';
else eval("\$str = $str;");
return $str;
}
//this
echo strtonum("(1<<10)*10"),'<br />';
echo strtonum("10*9.78"),'<br />';
//will output
10240
97.8
?>