note 33414 modified in function.bcmod by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:52:52 +0000 |
| Subject: | note 33414 modified in function.bcmod by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79877@lists.php.net to get a copy of this message | ||
Check a 10-digit barcode with the Modulo11-ckecksum like this:
<?php
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++ ) {
$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.
http://php.net/manual/en/function.bcmod.php