note 92603 deleted from function.eval by googleguy

From: Date: Fri, 24 Feb 2017 21:12:37 +0000
Subject: note 92603 deleted from function.eval by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208830@lists.php.net to get a copy of this message
Note Submitter: cmr at expansys dot com ---- Fixed matheval function when percentage is less than 10: <?php 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; } ?>

« previous php.notes (#208830) next »