You are here

function mod11_checksum in ISBN Field 6

3 calls to mod11_checksum()
generate_ISN_corrections in ./isbn.inc
ISN_checksum_OK in ./isbn.inc
ISN_classifier in ./isbn.inc

File

./isbn.inc, line 45

Code

function mod11_checksum($protostring, $weight) {
  $checksum = 0;
  $pos = 0;
  while ($pos < strlen($protostring) && $weight >= 1) {
    if ($protostring[$pos] >= '0' && $protostring[$pos] <= '9') {
      $checksum += $weight * $protostring[$pos];
      $weight--;
    }
    elseif ($weight == 1 && ($protostring[$pos] == 'X' || $protostring[$pos] == 'x')) {
      $checksum += 10;
      $weight--;
    }
    $pos++;
  }
  return $checksum % 11;
}