Results 1 to 11 of 11
Jan 1, 2013, 17:36 #1
- Join Date
- May 2006
- 1 Post(s)
- 0 Thread(s)
Generate Modulus 10 / Luhn Check Digit in PHP help?
Happy new year from Palo Alto! Please, I have been working for an inordinately long time trying to create some code for something that should be pretty basic. I have written some nice, simple PHP code that generates a random 11 digit alphanumeric codes, called $elevendigits, like this one:
What I now need to do is write some code that generates a check digit according to the Modulus 10 - - sometimes called Luhn - - standard. Let's call it it $checkdigit. It will be the twelfth digit.
I would have thought this an off-the-shelf function but, can't seem to get anything to work. It would need to:
1. Convert letters to numbers according to their ordinal place, starting with A=10, such that M=22, for example;
2. Starting with the right-most digit, multiply every other digit by 2;
3. Convert any two-digit products from the preceding step into 2 one-digit numbers;
4. Add all the digits together; and then
5. Subtract the sum from the next highest number ending in zero. This is the check digit.
Please, can anyone help me with the code necessary to accomplish this? I would have thought it easy, but am failing. Thank you sincerely!