Reply to Re: Invoice check number

Your name:

Reply:


Posted by Nel on 03/02/07 11:41

"McKirahan" <News@McKirahan.com> wrote in message
news:4q6dnbJCMIcnvXrYnZ2dnUVZ_uejnZ2d@comcast.com...
> "Kris" <Kristian.Nissen@gmail.com> wrote in message
> news:1172739986.866089.231740@j27g2000cwj.googlegroups.com...
>> I need to create a valid mod10 or luhn number that can be attached to
>> an invoice, I have found several examples showing how to validate a
>> credit card number or validate a number using mod10/luhn.
>>
>> Example:
>> invoice number = 700123
>> invoice check number 700123(checknumber)
>>
>> that check number should make the entire invoice number able to
>> validate using mod10/luhn
>
>
> Google is your friend.
>
> I cobbled this together from several sources; will it help?
>
> Validate it thoroughly before relying on it!
>
>
> <?php
> $inv = "700123";
> echo $inv . checkdigit($inv);
>
> function checkdigit($num) {
> /*
> * 1. Reverse the number
> * 2. Multiply all the digits in odd positions (The first digit, the third
> digit, etc) by 2.
> * 3. If any one is greater than 9 subtract 9 from it.
> * 4. Sum those numbers up
> * 5. Add the even numbered digits (the second, fourth, etc) to the number
> you got in the previous step
> * 6. The check digit is the amount you need to add to that number to make
> a multiple of 10.
> * So if you got 68 in the previous step the check digit would be 2.
> * You can calculate the digit in code using checkdigit = ((sum / 10 +
> 1) * 10 - sum) % 10
> * -- http://www.darkcoding.net/index.php/credit-card/luhn-formula/
> */
> $sum = 0;
> $pos = 0;
> $rev = strrev($num);
> $len = strlen($num);
> if ($len % 2 == 0) $len += 1;
> while ($pos < $len) {
> $odd = $rev[$pos] * 2;
> if ($odd > 9) {
> $odd -= 9;
> }
> $sum += $odd;
> if ($pos != ($len - 2)) {
> $sum += $rev[$pos +1];
> }
> $pos += 2;
> }
> return ((floor($sum/10) + 1) * 10 - $sum) % 10;
> }
> ?>
>
Hi

Your example works well but produces two Notices in php.

Nel.
Output follows:
_______________________________________________

Notice: Uninitialized string offset: 6 in luhn.php on line 23

Notice: Uninitialized string offset: 7 in luhn.php on line 29
7001233

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация