private function ISBNtest::get_isbn10_checkdigit in Biblio Advanced Import 6
Same name and namespace in other branches
- 7 lib/isbntest.class.php \ISBNtest::get_isbn10_checkdigit()
2 calls to ISBNtest::get_isbn10_checkdigit()
File
- lib/
isbntest.class.php, line 21
Class
Code
private function get_isbn10_checkdigit() {
if (strlen($this->isbn10) != 10) {
return FALSE;
$this->error = "Given ISBN-10 is not 10 digits (" . $this->isbn10 . ")";
}
/*
* this checkdigit calculation could probably be expressed in less
* space using a lop, but this keeps it very clear what the math
* involved is
*/
$checkdigit = 11 - (10 * substr($this->isbn10, 0, 1) + 9 * substr($this->isbn10, 1, 1) + 8 * substr($this->isbn10, 2, 1) + 7 * substr($this->isbn10, 3, 1) + 6 * substr($this->isbn10, 4, 1) + 5 * substr($this->isbn10, 5, 1) + 4 * substr($this->isbn10, 6, 1) + 3 * substr($this->isbn10, 7, 1) + 2 * substr($this->isbn10, 8, 1)) % 11;
/*
* convert the numeric check value
* into the single char version
*/
switch ($checkdigit) {
case 10:
$checkdigit = "X";
break;
case 11:
$checkdigit = 0;
break;
default:
}
return $checkdigit;
}