Windows tehnična podpora
Podporni forum za uporabnike storitev spletnega gostovanja
This forum is part of windows webhosting service at www.hostmachine.net
 


Calculate MOD11 control number

To je neaktivna kopija originalnega foruma, prirejena za lazje indeksiranje z iskalnimi roboti.
Klikni tukaj za prehod na aktivni forum.
Click here to go to original active forum.


 
       Windows tehnična podpora Seznam forumov -> PHP
Poglej prejšnjo temo :: Poglej naslednjo temo  
Avtor Sporočilo
Pico



Pridružen/-a: Ned Jan 2004 0:15
Prispevkov: 230
Kraj: HostMachine.net

Objavljeno: 7.7.2009, 21:08    Naslov sporočila: Calculate MOD11 control number  

Many banks use MOD 11 algorithm to calculate control number for verification whether the main number is correct or not, mostly to avoid input errors when typing.
Also, many reference numbers on bills or invoices use the same MOD11 algorithm to be safe from user typografic errors.

MOD 11 principle:

- first, you split given number into separate cyphers, for example:
125111
is split into
1 2 5 1 1 1

- then you take each cypher, and multiply it with so called "ponder". First ponder is 2, then 3, 4, 5, 6, etc... You start multiplying from the RIGHT side, and then SUM all results, for example:
1x2 + 1x3 + 1x4 + 5x5 + 2x6 + 1x7 = 53

- then you DIVIDE final result by 11 (it is MOD11, that's why 11), for example:
53 / 11 = 4 (with reminder of 9)

- Finally, you take reminder of latest calculation and substract it from 11 (yes, 11 again), for example:
11 - 9 = 2

And 2 is control number in MOD11 operation.

Ok, let's calculate MOD11 with PHP script:
Koda: function mod11($num) {
   $pond = 2;
   $sum = 0;
   $numRev = ereg_replace("[^0-9]", "", strrev($num));
   for($i=0;$i<strlen($numRev);$i++) {
      $currentNum = substr($numRev, $i, 1);
      $sum = $sum + (int)$currentNum * $pond;
      $pond++;
   }
   return 11-($sum-11*floor($sum/11));
}
Nazaj na vrh  
 
       Windows tehnična podpora Seznam forumov -> PHP
Stran 1 od 1


Te strani so generirane samo za lazje indexiranje z iskalnimi roboti.
Prosimo, da uporabite povezavo na glavni forum, kjer lahko aktivno sodelujete s svojimi prispevki