note 110264 added to function.preg-replace
| From: | espertalhao04 at hotmail dot com | Date: | Fri, 05 Oct 2012 21:57:20 +0000 |
| Subject: | note 110264 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191154@lists.php.net to get a copy of this message | ||
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...
----
Server IP: 194.8.30.16
Probable Submitter: 85.240.223.178
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/110264
Del: integrated -- https://master.php.net/note/delete/110264/integrated
Del: useless -- https://master.php.net/note/delete/110264/useless
Del: bad code -- https://master.php.net/note/delete/110264/bad+code
Del: spam -- https://master.php.net/note/delete/110264/spam
Del: non-english -- https://master.php.net/note/delete/110264/non-english
Del: in docs -- https://master.php.net/note/delete/110264/in+docs
Del: other reasons-- https://master.php.net/note/delete/110264
Reject -- https://master.php.net/note/reject/110264
Search -- https://master.php.net/manage/user-notes.php