note 71045 added to function.eval

From: Date: Thu, 09 Nov 2006 14:54:27 +0000
Subject: note 71045 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-119553@lists.php.net to get a copy of this message
A simple function to eval sum user's code for maths. <?php function strtonum($str) { $str = preg_replace('([^+\-*=/\(\)\d\^<>&|\.]*)','',$str); if(empty($str))$str = '0'; else eval("\$str = $str;"); return $str; } //this echo strtonum("(1<<10)*10"),'<br />'; echo strtonum("10*9.78"),'<br />'; //will output 10240 97.8 ?> ---- Server IP: 217.174.203.10 Probable Submitter: 86.68.0.176 ---- Manual Page -- http://www.php.net/manual/en/function.eval.php Edit -- https://master.php.net/note/edit/71045 Del: integrated -- https://master.php.net/note/delete/71045/integrated Del: useless -- https://master.php.net/note/delete/71045/useless Del: bad code -- https://master.php.net/note/delete/71045/bad+code Del: spam -- https://master.php.net/note/delete/71045/spam Del: non-english -- https://master.php.net/note/delete/71045/non-english Del: in docs -- https://master.php.net/note/delete/71045/in+docs Del: other reasons-- https://master.php.net/note/delete/71045 Reject -- https://master.php.net/note/reject/71045 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119553) next »