function generate_ISN_corrections in ISBN Field 6
2 calls to generate_ISN_corrections()
- generate_ISBN_corrections in ./isbn.inc
- generate_ISSN_corrections in ./isbn.inc
File
- ./isbn.inc, line 451
Code
function generate_ISN_corrections($ISN_proto, $length) {
$corrections = array();
$ISN_proto = ISN_clean($ISN_proto);
if (strlen($ISN_proto) == $length - 1) {
for ($pos = 0; $pos < $length - 1; $pos++) {
for ($i = 0; $i <= 9; $i++) {
$ISN_new = substr($ISN_proto, 0, $pos) . (string) $i . substr($ISN_proto, $pos);
if (ISN_checksum_OK($ISN_new, $length)) {
$corrections[canonical_ISN($ISN_new, $length)] = true;
}
}
}
if ($ISN_proto[$length - 2] != 'X') {
$ISN_new = $ISN_proto . make_checkdigit(mod11_checksum($ISN_proto, $length));
$corrections[canonical_ISN($ISN_new, $length)] = true;
}
}
elseif (strlen($ISN_proto) == $length) {
for ($pos = 0; $pos < $length - 1; $pos++) {
$current = $ISN_proto[$pos];
for ($i = 0; $i <= 9; $i++) {
$ISN_proto[$pos] = (string) $i;
if (ISN_checksum_OK($ISN_proto, $length)) {
$corrections[canonical_ISN($ISN_proto, $length)] = true;
}
}
$ISN_proto[$pos] = $ISN_proto[$pos + 1];
$ISN_proto[$pos + 1] = $current;
if ($ISN_proto[$pos] != 'X' && ISN_checksum_OK($ISN_proto, $length)) {
$corrections[canonical_ISN($ISN_proto, $length)] = true;
}
$ISN_proto[$pos + 1] = $ISN_proto[$pos];
$ISN_proto[$pos] = $current;
}
$ISN_proto[$length - 1] = make_checkdigit(mod11_checksum(substr($ISN_proto, 0, $length - 1), $length));
if (bad_ISN_char_count($ISN_proto) == 0) {
$corrections[canonical_ISN($ISN_proto, $length)] = true;
}
}
elseif (strlen($ISN_proto) == $length + 1) {
for ($pos = 0; $pos <= $length; $pos++) {
$ISN_new = substr($ISN_proto, 0, $pos) . substr($ISN_proto, $pos + 1);
if (ISN_checksum_OK($ISN_new, $length)) {
$corrections[canonical_ISN($ISN_new, $length)] = true;
}
}
}
return $corrections;
}