note 33414 added to function.bcmod
| From: | timo at in-timo dot de | Date: | Wed, 25 Jun 2003 11:15:51 +0000 |
| Subject: | note 33414 added to function.bcmod | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50982@lists.php.net to get a copy of this message | ||
Check a 10-digit barcode with the Modulo11-ckecksum like this:
function modulo11 ($barcode) {
$sum = 0;
FOR ( $i=0; $i<=8; $i++ ) {
$sub = substr($barcode, $i, 1);
$add = $sub * ($i+1);
$sum = $sum + $add; }
$modulo = bcmod($sum,11);
IF ( $modulo == 10 ) { $modulo = "X"; }
$sub = substr($barcode, 9, 1);
IF ( $sub == $modulo ) { return "true"; }
ELSE { return "false"; }
}
The function returns "true" if the barcode was read properly.
----
Manual Page -- http://www.php.net/manual/en/function.bcmod.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33414
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33414&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33414&report=yes