How to Intergrate ISBN Access on Your Webpages Using PHP

Posted in php by ShortLikeAFox on August 12th, 2008

ISBNs or International Standard Book Numbers are useful identifiers that can be used to find information about individual books. If you want to integrate ISBN lookups in your web applications PHP makes it doable.

Step One: ISBNdb.com is a has created an API that allows users from around the web to access their database of ISBN records. Here is their own description of the API:

ISBNdb.com’s remote access application programming interface (API) is designed to allow other websites and standalone applications use the vast collection of data collected by ISBNdb.com since 2003. As of this writing, in July 2005, the data includes nearly 1,800,000 books; almost 3,000,000 million library records; close to a million subjects; hundreds of thousands of author and publisher records parsed out of library data; more than 10,000,000 records of actual and historic prices.

To use this API you must first register. Registration takes literally seconds to complete. After this, you need to set up a key. Keys allow you to directly access the ISBN database from your own code. The ISBNdb.com website makes setting up keys easy.

Step Two: Now you’re start writing code to interact with the database. A request for an ISBN lookup will look something like this:

$isbnData = "http://isbndb.com/api/books.xml?access_key=XXXXXX&index1=isbn&value1=$isbnQuery";

You would insert your access key in the place of XXXXXX. $isbnQuery would be the isbn number you are interested in. $isbnData is an XML file. To access this data you need to let your code know what it is dealing with. Something like this will work:

$xmlData = @simplexml_load_file($isbnData) or die ("no file loaded") ;

Now you can access individual variables with calls similar to this:

$title = $xmData->BookList[0]->BookData[0]->Title ;

Here is a complete working example:

<?php

$searchQuery = "9780684801223"; //The ISBN for Ernest Hemingway’s Old Man and the Sea
$isbnData = "http://isbndb.com/api/books.xml?access_key=XXXXXX&index1=isbn&value1=$searchQuery"; //Remember to replace XXXXXX with your own access key
$xmlData = @simplexml_load_file($isbnData) or die ("no file loaded") ;
$title = $xmlData->BookList[0]->BookData[0]->Title ;
$authors = $xmlData->BookList[0]->BookData[0]->AuthorsText ;
$publisher = $xmlData->BookList[0]->BookData[0]->PublisherText ;

echo("$title<br/>");
echo("$authors<br/>");
echo("$publisher<br/>");

//This example prints:
//The old man and the sea
//Ernest Hemingway
//New York : Scribner Paperback Fiction, 1995.

?>

Leave a Comment