Given the first 9 digits of an ISBN-10, generate the check digit.

@param string $isbn The first 9 digits of an ISBN-10.

@return string      The check digit.
519423
public static function getISBN10CheckDigit($isbn)
    {
        $sum = 0;
        for ($x = 0; $x < strlen($isbn); $x++) {
            $sum += intval(substr($isbn, $x, 1)) * (1 + $x);
        }
        $checkdigit = $sum % 11;
        return $checkdigit == 10 ? 'X' : $checkdigit;
    }
798099
public function make13($isbn)
    {
        if(is_string($isbn) === false) {
            throw new Exception('Invalid parameter type.');
        }
        
        //Verify length
        $isbnLength = strlen($isbn);
        if ($isbnLength < 12 or $isbnLength > 13) {
            throw new Exception('Invalid ISBN-13 format.');
        }

        //Calculate check digit
        $check = 0;
        for ($i = 0; $i < 12; $i += 2) {
            $check += substr($isbn, $i, 1);
        }

        for ($i = 1; $i < 12; $i += 2) {
            $check += 3 * substr($isbn, $i, 1);
        }

        $check = 10 - $check % 10;
        if ($check === 10) {
            return 0;
        }
    
        return $check;
    }
1105204
public function getIsbn13() : ?string 
    {
        if ( ! $this->hasIsbn13()) {
            $this->setIsbn13($this->getDefaultIsbn13());
        }
        return $this->isbn13;
    }
266740
public static function of(string $isbn) : Isbn
    {
        if (preg_match(Internal\Regexp::ASCII, $isbn) === 0) {
            throw Exception\InvalidIsbnException::forIsbn($isbn);
        }

        $isbn = preg_replace(Internal\Regexp::NON_ALNUM, '', $isbn);

        if (preg_match(Internal\Regexp::ISBN13, $isbn) === 1) {
            if (! Internal\CheckDigit::validateCheckDigit13($isbn)) {
                throw Exception\InvalidIsbnException::forIsbn($isbn);
            }

            return new Isbn($isbn, true);
        }

        $isbn = strtoupper($isbn);

        if (preg_match(Internal\Regexp::ISBN10, $isbn) === 1) {
            if (! Internal\CheckDigit::validateCheckDigit10($isbn)) {
                throw Exception\InvalidIsbnException::forIsbn($isbn);
            }

            return new Isbn($isbn, false);
        }

        throw Exception\InvalidIsbnException::forIsbn($isbn);
    }
260128
public function isbn($isbn)
    {
        if ($this->check->is13($isbn))
            return $this->isbn13($isbn);
        if ($this->check->is10($isbn))
            return $this->isbn10($isbn);
        return false;
    }
91407
public static function checkIsbn10Number($isbn)
    {
        $isbn = trim($isbn);
        if (mb_strlen($isbn) !== 10 || preg_match('/0{10}/', $isbn)) {
            throw new MsgException("ISBN10 형식에 맞지 않습니다.");
        }

        $total = 0;
        for ($i = 0; $i < 9; $i++) {
            $digit = intval(substr($isbn, $i, 1));
            $total += ((10 - $i) * $digit);
        }

        $check_sum = (11 - ($total % 11)) % 11;
        if ($check_sum === 10) {
            $check_sum = 'X';
        }

        if ($check_sum != substr($isbn, 9)) {
            throw new MsgException("ISBN10 형식에 맞지 않습니다.");
        }
    }
1188188
public function get13()
    {
        // Is it invalid?
        if (!$this->isValid()) {
            return false;
        }
        // Is it an ISBN-10?  If so, convert to Bookland EAN:
        if (strlen($this->raw) == 10) {
            $start = '978' . substr($this->raw, 0, 9);
            return $start . self::getISBN13CheckDigit($start);
        }
        // If we made it this far, it must already be an ISBN-13; return as-is.
        return $this->raw;
    }
52620
public function getGroupName() : string
    {
        if ($this->rangeInfo === null) {
            throw IsbnException::unknownGroup($this->isbn);
        }

        return $this->rangeInfo->groupName;
    }
1346160
public function addHyphens($isbn, $char = '-')
    {
        if(is_string($isbn) === false ||
            is_string($char) === false) {
            throw new Exception('Invalid parameter type.');
        }
        
        $this->isbn = $isbn;
        $this->isbnSplit = array();
        
        if (strlen($this->isbn) === 13) {
            $this->isbnSplit[0] = substr($this->isbn, 0, 3);
        }

        $this->getRegistrationGroupElement();
        $this->getRegistrantElement();
        $this->getPublicationElement();
        $this->getCheckDigit();
        return implode($char, $this->isbnSplit);
    }
687782
def calculate_checksum(self):
        
        if len(self.isbn) in (9, 12):
            return calculate_checksum(self.isbn)
        else:
            return calculate_checksum(self.isbn[:-1])
690104
public static function ctype_digit($text)
    {
        $text = self::convert_int_to_char_for_ctype($text);

        return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text);
    }
827665
public function identify($isbn)
    {
        if($this->is10($isbn) === true) {
            return 10;
        }
        
        return ($this->is13($isbn) === true ? 13 : false);
    }
71623
public function format($format = 'EAN')
    {
        if (!$this->isValid()) {
            throw new \Exception('Cannot format invalid ISBN: '.$this->getErrors());
        }

        $this->calculateChecksum($format);

        $A = $this->getProduct();
        $B = $this->getCountry();
        $C = $this->getPublisher();
        $D = $this->getPublication();
        $E = $this->getChecksum();

        if ($format == 'ISBN-10') {
            return $B.'-'.$C.'-'.$D.'-'.$E;
        } elseif ($format == 'ISBN-13' || $format == 'ISBN') {
            return $A.'-'.$B.'-'.$C.'-'.$D.'-'.$E;
        } else {
            return $A.$B.$C.$D.$E;
        }
    }
1250999
public static function getCheckDigit(string $number) : int
    {
        if (! ctype_digit($number)) {
            throw new \InvalidArgumentException('The number must be a string of digits');
        }

        $checksum = self::checksum($number . '0');

        return ($checksum === 0) ? 0 : 10 - $checksum;
    }
1250797
private function createISBNText() {
        $isbn = '';
        if (!empty($this->text)) {
            // We try to create the ISBN Text... the hyphen really depends the ISBN agency.
            // We just put one before the checksum and one after the GS1 if present.
            $c = strlen($this->text);
            if ($c === 12 || $c === 13) {
                // If we have 13 characters now, just transform it temporarily to find the checksum...
                // Further in the code we take care of that anyway.
                $lastCharacter = '';
                if ($c === 13) {
                    $lastCharacter = $this->text[12];
                    $this->text = substr($this->text, 0, 12);
                }

                $checksum = $this->processChecksum();
                $isbn = 'ISBN ' . substr($this->text, 0, 3) . '-' . substr($this->text, 3, 9) . '-' . $checksum;

                // Put the last character back
                if ($c === 13) {
                    $this->text .= $lastCharacter;
                }
            } elseif ($c === 9 || $c === 10) {
                $checksum = 0;
                for ($i = 10; $i >= 2; $i--) {
                    $checksum += $this->text[10 - $i] * $i;
                }

                $checksum = 11 - $checksum % 11;
                if ($checksum === 10) {
                    $checksum = 'X'; // Changing type
                }

                $isbn = 'ISBN ' . substr($this->text, 0, 9) . '-' . $checksum;
            }
        }

        return $isbn;
    }
292430
private function getRegistrationGroupElement()
    {
        if (isset($this->isbnSplit[0]) === false or $this->isbnSplit[0] === '978') {
            $this->range("0000000", "5999999", 1, 1);
            $this->range("6000000", "6499999", 3, 1);
            $this->range("6500000", "6999999", 0, 1);
            $this->range("7000000", "7999999", 1, 1);
            $this->range("8000000", "9499999", 2, 1);
            $this->range("9500000", "9899999", 3, 1);
            $this->range("9900000", "9989999", 4, 1);
            $this->range("9990000", "9999999", 5, 1);
        }

        if (isset($this->isbnSplit[0]) === true and $this->isbnSplit[0] === '979') {
            $this->range("0000000", "0999999", 0, 1);
            $this->range("1000000", "1199999", 2, 1);
            $this->range("1200000", "9999999", 0, 1);
        }

        return (isset($this->isbnSplit[1]));
    }
158868
public function getDigit($p_digit)
    {
        if (array_key_exists($p_digit, $this->digits)) {
            return $this->digits[$p_digit];
        }

        throw new NumbersWordsException(sprintf('Can\'t find digit %s !', $p_digit));
    }