function isbn10_to_13($isbnold){
if (strlen($isbnold) != 10){ // Make sure we have a 10 digit string to start
return 'Invalid ISBN-10, must be 10 digits';
}
// prefix with 978 and drop old checksum (last digit)
$isbn = '978'.substr($isbnold,0,9);
for ($i = 0; $i <= 12; $i++){ // For each digit if new isbn
$weight = ($i%2 == 0)? 1 : 3; // Alternate between 1's and 3's
$check_sum_total = $check_sum_total + ($isbn{$i} * $weight); // multiply each digit by 1 or 3 and add to $checksumtotal
}
$new_check_sum = 10 - ($check_sum_total%10); // Modulus 10 business
return ($isbn.$new_check_sum); //add checksum on to end and return
}
Thanks to bloom.co.uk
Post new comment