note 33414 deleted from function.bcmod by didou
| From: | didou@php.net | Date: | Sat, 27 Jan 2007 16:55:39 +0000 |
| Subject: | note 33414 deleted from function.bcmod by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122271@lists.php.net to get a copy of this message | ||
Note Submitter: timo at in-timo dot de
----
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.