Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33861 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65778 invoked by uid 1010); 8 Dec 2007 01:50:28 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 65763 invoked from network); 8 Dec 2007 01:50:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Dec 2007 01:50:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=ceo@l-i-e.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ceo@l-i-e.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain l-i-e.com from 67.139.134.202 cause and error) X-PHP-List-Original-Sender: ceo@l-i-e.com X-Host-Fingerprint: 67.139.134.202 o2.hostbaby.com FreeBSD 4.7-5.2 (or MacOS X 10.2-10.3) (2) Received: from [67.139.134.202] ([67.139.134.202:3505] helo=o2.hostbaby.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 60/71-51565-268F9574 for ; Fri, 07 Dec 2007 20:50:26 -0500 Received: (qmail 93356 invoked by uid 98); 8 Dec 2007 01:50:28 -0000 Received: from 127.0.0.1 by o2.hostbaby.com (envelope-from , uid 1013) with qmail-scanner-2.01 (clamdscan: 0.88.7/5028. Clear:RC:1(127.0.0.1):. Processed in 0.080368 secs); 08 Dec 2007 01:50:28 -0000 Received: from localhost (HELO l-i-e.com) (127.0.0.1) by localhost with SMTP; 8 Dec 2007 01:50:28 -0000 Received: from 98.193.37.55 (SquirrelMail authenticated user ceo@l-i-e.com) by www.l-i-e.com with HTTP; Fri, 7 Dec 2007 19:50:28 -0600 (CST) Message-ID: <47882.98.193.37.55.1197078628.squirrel@www.l-i-e.com> In-Reply-To: <01.E6.00959.D3E59574@pb1.pair.com> References: <01.E6.00959.D3E59574@pb1.pair.com> Date: Fri, 7 Dec 2007 19:50:28 -0600 (CST) To: nrixham@gmail.com Cc: internals@lists.php.net Reply-To: ceo@l-i-e.com User-Agent: Hostbaby Webmail MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Subject: Re: [PHP-DEV] Thoughts on Feature Request - Arithmetic From: ceo@l-i-e.com ("Richard Lynch") I suspect you could address security concerns by limiting the input to valid characters in your arithmetic needs: if (preg_match('|^[0-9.+/*-]+$|', $expression)){ eval("$foo = $expression"); return $foo; } On Fri, December 7, 2007 8:51 am, Nathan Rixham wrote: > In-Built PHP Functions for parsing of basic arithmetic and if possible > fraction to decimal and decimal to fraction > > $arithmetic_string = "3*5"; > echo arith($arithmetic_string); // returns float 15 > > $arithmetic_string = "1/2"; > echo arith($arithmetic_string); // returns float 0.5 > > $fraction_string = "1/4"; > echo fracdec($fraction_string); // returns float 0.25 > > $dec_string = "0.5"; > echo decfrac($dec_string); // returns string "1/4" > > I've used php for years, came accross the need for this today and was > suprised such a basic command wasn't there.. currently the only way I > can see to do it would be to eval.. which isn't the most secure method > for such a basic need. > > Regards > > Nathan > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So?