note 92603 added to function.eval

From: Date: Fri, 31 Jul 2009 07:20:31 +0000
Subject: note 92603 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-158938@lists.php.net to get a copy of this message
Fixed matheval function when percentage is less than 10: function matheval($equation) { $equation = preg_replace("/[^0-9+\-.*\/()%]/","",$equation); // fix percentage calcul when percentage value < 10 $equation = preg_replace("/([+-])([0-9]{1})(%)/","*(1\$1.0\$2)",$equation); // calc percentage $equation = preg_replace("/([+-])([0-9]+)(%)/","*(1\$1.\$2)",$equation); // you could use str_replace on this next line // if you really, really want to fine-tune this equation $equation = preg_replace("/([0-9]+)(%)/",".\$1",$equation); if ( $equation == "" ) { $return = 0; } else { eval("\$return=" . $equation . ";" ); } return $return; } ---- Server IP: 69.147.83.197 Probable Submitter: 193.253.223.102 ---- Manual Page -- http://www.php.net/manual/en/function.eval.php Edit -- https://master.php.net/note/edit/92603 Del: integrated -- https://master.php.net/note/delete/92603/integrated Del: useless -- https://master.php.net/note/delete/92603/useless Del: bad code -- https://master.php.net/note/delete/92603/bad+code Del: spam -- https://master.php.net/note/delete/92603/spam Del: non-english -- https://master.php.net/note/delete/92603/non-english Del: in docs -- https://master.php.net/note/delete/92603/in+docs Del: other reasons-- https://master.php.net/note/delete/92603 Reject -- https://master.php.net/note/reject/92603 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158938) next »