I have found a PHP script github ISBN-Calc Routine to perform the ISBN-10 checksum calculation:
<?php
/**
* Calculate ISBN checksum
*
* @param string $isbn
* @return integer
*/
function isbn_checksum($isbn) {
$sum = 0; $isbn = str_split(preg_replace('/[^\d]/', '', $isbn));
foreach($isbn as $key => $z) {
if($key >= 12) break;
$sum += ($key % 2) ? $z * 3 : $z;
}
$checksum = (10 - $sum % 10);
return ($checksum == 10) ? 0 : $checksum;
}
But f.e for my ISBN-10: 0470173424
I get Checksum: 0
with this github script.
Accoring to ISBN online checker the checksum should be 4 as is it in the ISBN. Can anyone here provide me with the correct PHP routine, please?
Thanks