note 29020 deleted from function.eval by victor

From: Date: Sat, 12 Jun 2004 22:35:58 +0000
Subject: note 29020 deleted from function.eval by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-70993@lists.php.net to get a copy of this message
Note Submitter: Taras Young ---- A quick and simple (and hopefully safe) method of evaluating sums: function evalsum($sum){ // Sum may only contain the following characters: $check = strtr($sum, "0123456789+-*/()", " "); if ( trim($check) == "" ) { $to_eval="\$evalled=" . $sum . ";"; eval($to_eval); }else{ $evalled = "Evaluation error"; } return $evalled; } echo evalsum("2+2"); Unfortunately, since PHP uses pow(a,b) for powers rather than a^b, this won't do powers.

« previous php.notes (#70993) next »