note 33414 modified in function.bcmod by pollita
| From: | pollita@php.net | Date: | Wed, 25 Jun 2003 15:39:46 +0000 |
| Subject: | note 33414 modified in function.bcmod by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-50996@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++ ) {
$add = $barcode{$i} * ($i+1);
$sum = $sum + $add;
}
$modulo = $sum % 11;
IF ( $modulo == 10 ) { $modulo = "X"; }
IF ( $barcode{9} == $modulo ) {
return true;
} ELSE {
return false;
}
}
The function returns "true" if the barcode was read properly.
--was--
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.
http://www.php.net/manual/en/function.bcmod.php