You are here

private function ISBNtest::get_isbn13_checkdigit in Biblio Advanced Import 7

Same name and namespace in other branches
  1. 6 lib/isbntest.class.php \ISBNtest::get_isbn13_checkdigit()
2 calls to ISBNtest::get_isbn13_checkdigit()
ISBNtest::get_isbn13 in lib/isbntest.class.php
ISBNtest::valid_isbn13 in lib/isbntest.class.php

File

lib/isbntest.class.php, line 53

Class

ISBNtest

Code

private function get_isbn13_checkdigit() {
  if (strlen($this->isbn13) != 13) {
    return FALSE;
    $this->error = "Given ISBN-13 is not 10 digits (" . $this->isbn13 . ")";
  }

  /*
   * 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 = 10 - (1 * substr($this->isbn13, 0, 1) + 3 * substr($this->isbn13, 1, 1) + 1 * substr($this->isbn13, 2, 1) + 3 * substr($this->isbn13, 3, 1) + 1 * substr($this->isbn13, 4, 1) + 3 * substr($this->isbn13, 5, 1) + 1 * substr($this->isbn13, 6, 1) + 3 * substr($this->isbn13, 7, 1) + 1 * substr($this->isbn13, 8, 1) + 3 * substr($this->isbn13, 9, 1) + 1 * substr($this->isbn13, 10, 1) + 3 * substr($this->isbn13, 11, 1)) % 10;

  /*
   * convert the numeric check value
   * into the single char version
   */
  if ($checkdigit == 10) {
    $checkdigit = "0";
  }
  return $checkdigit;
}