Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33837 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33510 invoked by uid 1010); 7 Dec 2007 16:21:06 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 33495 invoked from network); 7 Dec 2007 16:21:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Dec 2007 16:21:06 -0000 X-Host-Fingerprint: 82.41.129.160 82-41-129-160.cable.ubr02.glen.blueyonder.co.uk Received: from [82.41.129.160] ([82.41.129.160:5881] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/C2-16679-2F279574 for ; Fri, 07 Dec 2007 11:21:06 -0500 Message-ID: To: internals@lists.php.net Date: Fri, 07 Dec 2007 16:19:18 +0000 Reply-To: nrixham@gmail.com User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 References: <01.E6.00959.D3E59574@pb1.pair.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 82.41.129.160 Subject: Re: [PHP-DEV] Thoughts on Feature Request - Arithmetic From: nrixham@gmail.com (Nathan Rixham) Daniel and Derick, thanks for the replies.. Daniel first.. is great :) however $arithmetic_string = "3*5"; $arithmetic_value = arith($arithmetic_string); not possible with the method you mentioned. eval() yes this works, however personally I feel a simple arith() (or more suitably named function) would be a great deal quicker and safer than eval($_POST['sum']), the security dangers are somewhat obvious. ps: I must point out that I've still never had a use for this and never would (perhaps the fraction??), but somebody over on a dev forum does, and I was quite suprised this functionality wasn't included! :P Nathan Daniel Brown wrote: > On Dec 7, 2007 9:51 AM, Nathan Rixham wrote: >> In-Built PHP Functions for parsing of basic arithmetic and if possible >> fraction to decimal and decimal to fraction > > PHP already handles half of what you're looking for by default. > >> $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" > > Now I see why you need PHP to do your math for you! ;-P > > There are functions written that do this now though. > >> 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 >> >> > > >