[Koha-devel] Retrieving 10-digit ISBNs in a report

Nicholas van Oudtshoorn vanoudt at gmail.com
Thu Mar 8 06:49:58 CET 2012


A simple bit of code can be used to get the first valid 10-digit ISBN. 
This is the php code we use - it could be adapted to perl quite easily, 
though.... (Actually, if I recall correctly, there is a C4 function to 
get the Normalised ISBN...)

// Normalise the ISBN
$isbn = preg_replace('/(.*) \| (.*)/', '$1', $isbn); // Get first isbn
$isbn = preg_replace('/(.*) (.*)/', '$1', $isbn); // Get rid of text
if (strlen($isbn) == 11) {
   if ($debugging) { print "Chopping 11 digit ISBN to a 10 digit ISBN"; }
   $isbn = substr($isbn,1,10);
} else if (strlen($isbn) == 13) {
   $isbn = substr($isbn,3,9);
   $checksum = 0;
   $weight = 10;
   $isbnCharArray = str_split($isbn);
   foreach($isbnCharArray as $char) {
     $checksum += $char * $weight;
     $weight--;
   }
   $checksum = 11-($checksum % 11);
   if ($checksum == 10) {
     $isbn += "X";
   } else if ($checksum == 11) {
     $isbn += "0";
   } else {
     $isbn .= $checksum;
   }
} else if (strlen($isbn) != 10) {
   if ($debugging) { print "<p>Illegal ISBN Found: $isbn</p>"; }
     exit;
}
if ($debugging) { print "Normalised ISBN: $isbn"; exit; }


-
Nick

On 03/07/2012 05:50 AM, Cab Vinton wrote:
> Hi, All --
>
> For the purposes of creating a web-based carousel of book covers of
> our recent acquisitions, I'd like to run a report that generates a
> list of ISBNs of items added between 2 dates.
>
> Amazon&  therefore Koha rely on 10-digit ISBNs for book cover retrieval.
>
> However, when I run a report using biblioitems.isbn, this is the
> output I get. Many truncated ISBNs, presumably because the max length
> = 30 restriction.
>
> 9780425243244 (pbk.) | 0425243
> 9780307718099 | 0307718093
> 0804840288 | 9780804840286 (tr
> 9780811876377 : | 0811876373 :
> 1569244677
> 9781400064588 (acidfree paper)
> 9780061429255 | 0061429252
> 9781451661064 (hardcover) | 14
>
> Is there a way to run a report that outputs only the 10 digit ISBNs?
>
> Many thanks,
>
> Cab Vinton, Director
> Sanbornton Public Library
> Sanbornton, NH
> _______________________________________________
> Koha-devel mailing list
> Koha-devel at lists.koha-community.org
> http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
> website : http://www.koha-community.org/
> git : http://git.koha-community.org/
> bugs : http://bugs.koha-community.org/
>




More information about the Koha-devel mailing list