private function validateISBN13Checksum($isbnNr, &$error)
    {
        if (!$isbnNr) {
            return false;
        }

        if (strlen($isbnNr) !== self::ISBN13_LENGTH) {
            $error = 'ISBN-13 must be 13 digit, digit count is: ' . strlen($isbnNr);

            return false;
        }

        if (substr($isbnNr, 0, self::ISBN13_PREFIX_LENGTH) !== self::ISBN13_PREFIX_978 &&
             substr($isbnNr, 0, self::ISBN13_PREFIX_LENGTH) !== self::ISBN13_PREFIX_979) {
            $error = 'ISBN-13 value must start with 978 or 979, got: ' . substr($isbnNr, 0, self::ISBN13_PREFIX_LENGTH);

            return false;
        }

        $checksum13 = 0;
        $weight13 = 1;
        //compute checksum
        $val = 0;
        for ($i = 0; $i < self::ISBN13_LENGTH; ++$i) {
            $val = $isbnNr[$i];
            if (!is_numeric($isbnNr[$i])) {
                $error = 'All ISBN-13 characters need to be numeric';

                return false;
            }
            $checksum13 = $checksum13 + $weight13 * $val;
            $weight13 = ($weight13 + 2) % 4;
        }
        if (($checksum13 % 10) !== 0) {
            // Calculate the last digit from the 12 first numbers.
            $checkDigit = (10 - (($checksum13 - (($weight13 + 2) % 4) * $val) % 10)) % 10;
            //bad checksum
            $error = 'Bad checksum, last digit of ISBN-13 should be ' . $checkDigit;

            return false;
        }

        return true;
    }
private function validateISBN13Checksum($isbnNr, &$error)
    {
        if (!$isbnNr) {
            return false;
        }

        if (strlen($isbnNr) !== self::ISBN13_LENGTH) {
            $error = 'ISBN-13 must be 13 digit, digit count is: ' . strlen($isbnNr);

            return false;
        }

        if (substr($isbnNr, 0, self::ISBN13_PREFIX_LENGTH) !== self::ISBN13_PREFIX_978 &&
             substr($isbnNr, 0, self::ISBN13_PREFIX_LENGTH) !== self::ISBN13_PREFIX_979) {
            $error = 'ISBN-13 value must start with 978 or 979, got: ' . substr($isbnNr, 0, self::ISBN13_PREFIX_LENGTH);

            return false;
        }

        $checksum13 = 0;
        $weight13 = 1;
        //compute checksum
        $val = 0;
        for ($i = 0; $i < self::ISBN13_LENGTH; ++$i) {
            $val = $isbnNr[$i];
            if (!is_numeric($isbnNr[$i])) {
                $error = 'All ISBN-13 characters need to be numeric';

                return false;
            }
            $checksum13 = $checksum13 + $weight13 * $val;
            $weight13 = ($weight13 + 2) % 4;
        }
        if (($checksum13 % 10) !== 0) {
            // Calculate the last digit from the 12 first numbers.
            $checkDigit = (10 - (($checksum13 - (($weight13 + 2) % 4) * $val) % 10)) % 10;
            //bad checksum
            $error = 'Bad checksum, last digit of ISBN-13 should be ' . $checkDigit;

            return false;
        }

        return true;
    }
private function validateISBN13Checksum ( $ isbnNr , & $ error ) { if ( ! $ isbnNr ) { return false ; } if ( strlen ( $ isbnNr ) !== self :: ISBN13_LENGTH ) { $ error = 'ISBN-13 must be 13 digit, digit count is: ' . strlen ( $ isbnNr ) ; return false ; } if ( substr ( $ isbnNr , 0 , self :: ISBN13_PREFIX_LENGTH ) !== self :: ISBN13_PREFIX_978 && substr ( $ isbnNr , 0 , self :: ISBN13_PREFIX_LENGTH ) !== self :: ISBN13_PREFIX_979 ) { $ error = 'ISBN-13 value must start with 978 or 979, got: ' . substr ( $ isbnNr , 0 , self :: ISBN13_PREFIX_LENGTH ) ; return false ; } $ checksum13 = 0 ; $ weight13 = 1 ; //compute checksum $ val = 0 ; for ( $ i = 0 ; $ i < self :: ISBN13_LENGTH ; ++ $ i ) { $ val = $ isbnNr [ $ i ] ; if ( ! is_numeric ( $ isbnNr [ $ i ] ) ) { $ error = 'All ISBN-13 characters need to be numeric' ; return false ; } $ checksum13 = $ checksum13 + $ weight13 * $ val ; $ weight13 = ( $ weight13 + 2 ) % 4 ; } if ( ( $ checksum13 % 10 ) !== 0 ) { // Calculate the last digit from the 12 first numbers. $ checkDigit = ( 10 - ( ( $ checksum13 - ( ( $ weight13 + 2 ) % 4 ) * $ val ) % 10 ) ) % 10 ; //bad checksum $ error = 'Bad checksum, last digit of ISBN-13 should be ' . $ checkDigit ; return false ; } return true ; }
Validates the ISBN-13 number.

@param string $isbnNr A string containing the number without any dashes.
@param string $error is used to send back an error message that will be shown to the user if the
ISBN number validated.

@return bool
Validates the ISBN - 13 number .