/** funkce pro prevod ISBN, EAN, ... na 13-ti mistny format **/ function check_isbn($value) { /* Remove spaces, dots, and hyphens from the ISBN */ $isbn = str_replace(array(' ', '-', '.'), '', $value); /* Figure out how long the remaining string is */ $length = strlen($isbn); /* Set the checkdigit to the last character in the string */ $checkdigit = substr($isbn, -1); /* Take action based on the length of the string */ switch ($length) { case "10": // If the isbn is 10 digits, do the following /* Check to see if the first 9 digits are numeric */ if (is_numeric(substr($isbn, -10, 9))) { /* Check to see if the checkdigit is a number -- if it is, leave it alone. If it is not, convert it to uppercase. */ $checkdigit = (!is_numeric($checkdigit)) ? $checkdigit : strtoupper($checkdigit); /* Check to see if the checkdigit is X -- if it is, set it to 10, if it isn't, leave it alone. */ $checkdigit = ($checkdigit == "X") ? "10" : $checkdigit; /* Initialize $sum to 0 */ $sum = 0; /* Cycle through, adding up the numbers */ for ($i = 0; $i < 9; $i++) { $sum = $sum + ($isbn[$i] * (10 - $i)); } /* Add the checkdigit at the end */ $sum = $sum + $checkdigit; /* Does it divide like it is supposed to? */ $mod = $sum % 11; if ($mod == 0) { // If so, display a success message //print "

" . $isbn . " is a good ISBN.
\n"; /* Now figure out the 13 digit equivalent */ $newisbn = substr($isbn, -10, 9); // drop the checkdigit $newisbn = "978" . $newisbn; // Add 978 prefix /* Run through the new first 12 digits, weighting them alternately by 1 and 3, sum them up */ $sum = $newisbn[0] + ($newisbn[1] * 3) + $newisbn[2] + ($newisbn[3] * 3) + $newisbn[4] + ($newisbn[5] * 3) + $newisbn[6] + ($newisbn[7] * 3) + $newisbn[8] + ($newisbn[9] * 3) + $newisbn[10] + ($newisbn[11] * 3); /* Get the remainder when the sum is divided by 10 */ $mod = $sum % 10; /* Calculate the new checkdigit */ $checkdigit = 10 - $mod; /* If $checkdigit is 10, change it to 0. Otherwise leave as-is. */ //$checkdigit = ($checkdigit == "10") ? "0" : $correct_checkdigit; if ($checkdigit == "10") $checkdigit = 0; /* Append it to the first 12 digits */ $newisbn = $newisbn . $checkdigit; /* Print it out */ //print "When converted to ISBN-13, " . $isbn . " becomes " . $newisbn . ".

\n"; $vystup = $newisbn; } // end if checking to see if the 10 digit isbn was good } // end if is_numeric(substr($isbn, -10, 9) else { //display_error("bad checkdigit"); // If not, display an error $vystup = "error"; } break; case "12": // If the isbn is 10 digits, do the following $chech_num = 10-(($isbn[0]*1+$isbn[1]*3+$isbn[2]*1+$isbn[3]*3+$isbn[4]*1+$isbn[5]*3+$isbn[6]*1+$isbn[7]*3+$isbn[8]*1+$isbn[9]*3+$isbn[10]*1+$isbn[11]*3) % 10); $vystup = $isbn.$chech_num; //echo "doplnit na 13 znaku"; //https://en.wikipedia.org/wiki/International_Standard_Book_Number break; case "13": // If the isbn is 13 digits, do the following /* Run through the new first 12 digits, weighting them alternately by 1 and 3, sum them up */ $sum = $isbn[0] + ($isbn[1] * 3) + $isbn[2] + ($isbn[3] * 3) + $isbn[4] + ($isbn[5] * 3) + $isbn[6] + ($isbn[7] * 3) + $isbn[8] + ($isbn[9] * 3) + $isbn[10] + ($isbn[11] * 3); /* Get the remainder when the sum is divided by 10 */ $mod = $sum % 10; /* Calculate the new checkdigit */ $correct_checkdigit = 10 - $mod; /* If $checkdigit is 10, change it to 0. Otherwise leave as-is. */ $correct_checkdigit = ($correct_checkdigit == "10") ? "0" : $correct_checkdigit; /* Compare the two checkdigits */ if ($checkdigit == $correct_checkdigit) { $vystup = $isbn; //print "

\n" . $isbn . " is a valid ISBN.

\n\n"; // Success } else { $vystup = "error"; //display_error("bad checkdigit"); } break; default: // If the isbn is neither 10 nor 13 digits, display an error $vystup = "error"; //display_error("invalid length"); break; } // end switch return $vystup; } /** funkce na prevod ISSN na 13-ti mistny format **/ function issn_convert($value) { //https://cs.wikipedia.org/wiki/International_Standard_Serial_Number //info //https://www.barcodefaq.com/1d/issn/ // postup $vystup = "977".$value[0].$value[1].$value[2].$value[3].$value[5].$value[6].$value[7]."00"; $check = (((($vystup[1]+$vystup[3]+$vystup[5]+$vystup[7]+$vystup[9]+$vystup[11]) * 3) + ($vystup[0]+$vystup[2]+$vystup[4]+$vystup[6]+$vystup[8]+$vystup[10]))); $round = round($check, -1, PHP_ROUND_HALF_UP); if ($round <= $check) $round=$round+10; $value = $round - $check; if ($value == '10') $value = 1; $value = $vystup.$value; return $value; }