php3-list | 199807
Date: 07/30/98
- Next message: Brian Schaffner: "RE: [PHP3] apache1.3.1 not reading srm.conf-little off topic"
- Previous message: Verle Harrison: "[PHP3] apache1.3.1 not reading srm.conf-little off topic"
- In reply to: Stefan Powell: "Re: [PHP3] Credit Card"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Stefan Powell wrote:
> <?php
> //Stefan's slightly obfuscated, but much improved LUHNMod10
> function LUHNMod10($ccnum) {
> if (!isset($ccnum)) return FALSE;
> $sum = 0;
> $len = strlen($ccnum);
> $ccnum=ereg_replace('[^[:digit:]]+','',$ccnum);
> for($idx=0;$idx<$len;$idx++) {
>...
Whoa! HUGE error in that function... I should set the length after
stipping the non-digits.
//Stefan's slightly obfuscated, but much MUCH improved LUHNMod10
function LUHNMod10($ccnum) {
if (!isset($ccnum)) return FALSE;
$ccnum=ereg_replace('[^[:digit:]]+','',$ccnum);
$sum = 0;
$len = strlen($ccnum);
for($idx=0;$idx<$len;$idx++) {
$digit = substr($ccnum,$idx,1);
if ($idx%2) {$sum += ($digit >= 5) ? 1+(($digit*2)%10) : $digit*2;}
else {$sum += $digit;}
}
if ($sum%10) return FALSE;
return TRUE;
}
--Stef
-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3
- Next message: Brian Schaffner: "RE: [PHP3] apache1.3.1 not reading srm.conf-little off topic"
- Previous message: Verle Harrison: "[PHP3] apache1.3.1 not reading srm.conf-little off topic"
- In reply to: Stefan Powell: "Re: [PHP3] Credit Card"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

