Re: [PATCH] removed Date_Calc dependency on PCRE

From: Date: Sat, 19 Jul 2003 18:29:12 +0000
Subject: Re: [PATCH] removed Date_Calc dependency on PCRE
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-18439@lists.php.net to get a copy of this message
# swalk@prp.physik.tu-darmstadt.de / 2003-07-19 19:57:10 +0200: > On Sat, Jul 19, 2003 at 07:33:47PM +0200, Roman Neuhauser wrote: > > 1. this was the only preg_*() call in the whole file > > 2. is_numeric() does the same job, even faster > > It is not doing the /same/ job. something like "1.12" or ".1e3" will > pass through is_numeric and not through that preg_match... oh, you're right. > i'd use ctype_digit, or if you don't want to use "new" functions, > strspn to check for that... ok, another patch, this time with strspn(). is this one ok? -- If you cc me or remove the list(s) completely I'll most likely ignore your message. see http://www.eyrie.org./~eagle/faqs/questions.html

Index: Date/Date/Calc.php =================================================================== RCS file: /repository/pear/Date/Date/Calc.php,v retrieving revision 1.13 diff -u -u -r1.13 Calc.php --- Date/Date/Calc.php 21 Jun 2003 09:45:51 -0000 1.13 +++ Date/Date/Calc.php 19 Jul 2003 18:27:07 -0000 @@ -90,11 +90,7 @@ $year = Date_Calc::dateNow('%Y'); } - if (strlen($year) != 4) { - return false; - } - - if (preg_match('/\D/',$year)) { + if (strlen($year) != 4 || strspn($year, '0123456789') != 4) { return false; }
« previous php.pear.dev (#18439) next »