function isbn_check_13 in ISBN Field 6.0
Same name and namespace in other branches
- 7 isbn.module \isbn_check_13()
2 calls to isbn_check_13()
File
- ./
isbn.module, line 161 - Maintains a consistant relationship between nodes and ISBNs.
Code
function isbn_check_13($isbn) {
$weight = 1;
for ($i = 0; $i < 12; $i++) {
$digit = substr($isbn, $i, 1);
$total = $total + $digit * $weight;
//drupal_set_message(' i '.$i.' digit '.$digit.' x '.$weight.'Total '.$total);
if ($weight == 1) {
$weight = 3;
}
else {
$weight = 1;
}
}
$remainder = $total % 10;
$check = 10 - $remainder;
if ($check == 10) {
$check = '0';
}
return $check;
}