public static function getISBN13CheckDigit($isbn)
    {
        $sum = 0;
        $weight = 1;
        for ($x = 0; $x < strlen($isbn); $x++) {
            $sum += intval(substr($isbn, $x, 1)) * $weight;
            $weight = $weight == 1 ? 3 : 1;
        }
        $retval = 10 - ($sum % 10);
        return $retval == 10 ? 0 : $retval;
    }