note 110264 deleted from function.preg-replace by danbrown
| From: | danbrown@php.net | Date: | Wed, 17 Oct 2012 21:27:51 +0000 |
| Subject: | note 110264 deleted from function.preg-replace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191405@lists.php.net to get a copy of this message | ||
Note Submitter: espertalhao04 at hotmail dot com
----
function _n($a)
{
return eval("echo ".preg_replace("/([^\d+\-*.\\\(\) ])/","",
str_replace(array("0(","1(","2(","3(","4(","5(","6(","7(","8(","9("),
array("0*(","1*(","2*(","3*(","4*(","5*(","6*(","7*(","8*(","9*("),"$a")).";");
}
a simple and very bad function to make math calculus from a string, plus it supports things like
3(6)+0(9);
echo _n("2(1)-5+1(3)"); //returns 0 cause 2*1-5+1*3 = 2-5+3 = 2+3-5 = 5-5 = 0
i hope someone finds this usefull...
by the way: optimization is required for this to work better, like a good regex, that i had a bunch
of troubles...