Getting books details by ISBN in PHP

Sometimes I love being a geek. Today, as I set out to inventory my collection of almost 500 books or so, I wanted to find a fast way to get the information on the book I wanted based on the books ISBN. This was because I was already getting tired of typing five books into the inventory (yes, I am that lazy) and I really did not want to keep typing out the authors name, the title and the subtitle for each book.

So I went to and entered an ISBN thinking I would be able to just copy and paste the book information from the output. That turned out to be overwhelmingly difficult since their output of the search is really convoluted. I knew what I wanted to get and they didn’t offer that.

But they did offer an API and, after reading their docs, I realized that I could write a script that would take an ISBN and return to me the information I was looking for in a way that I could just copy and paste it. Remarkably, it was faster and easier than I thought it would be. I actually developed this little snippet, freely available for you here, in about 5 minutes. Hope it helps you in some way, if you are looking for such a thing.

NOTE: Before using this code make sure to sign up for your own API key. In order to do that you will need to register for an account with and then create a key. But as soon as you do you will have immediate access to their API. The API is simple, responding to the request with a simple XML output. Anyhow, without further ado, here is the little script I put together to fetch me the data I was looking for the way I wanted it.

 * Set this value to your own API key
$apikey = '12345678';
 * Initialize this var for use when forms are not posted
$isbn = null;
 * Initialize the result set var
$rs = null;
 * See if the form is posted
   * Get the ISBN from the form
   * No, there is no validation on this. This 
   * was for me and I knew I would not be at
   * all trying to trick my own script. USE 
  $isbn = $_POST['isbn'];
   * Get the result as a SimpleXML object
  $rs = simplexml_load_file("$apikey&index1=isbn&value1=$isbn");
<head><title>ISBN Check</title></head>
<form method="post" action="<?php echo basename(__FILE__) ?>">
    Enter an ISBN:<br />
    <input type="text" size="40" name="isbn" id="isbn" value="<?php echo $isbn ?>" />
    <input type="submit" name="submit" value="Search ISBN" />
 * Only output more stuff if there is a result
if ($rs) : ?>
<hr />
Results for ISBN: <?php echo $isbn ?>:
 * Results for a book are in $rs->BookList->BookData
 * You can see this using var_dump($rs);
$book = $rs->BookList->BookData;
  <strong><?php echo $book->Title; ?></strong><br />
  <?php echo !empty($book->TitleLong) ? $book->TitleLong . '<br />' : null; ?>
  <?php echo $book->AuthorsText; ?><br />
  <?php echo $book->PublisherText; ?><br />
  <?php echo $isbn; ?>
<?php endif; ?>

Typical output might look like (from one of the books I was checking on):

Results for ISBN: 0316116955:

The day the universe changed
James Burke
Boston : Little, Brown, c1985.

I hope you enjoy this, if you happen to be looking for an ISBN search tool that you can run on your own. 😉

14 Replies to “Getting books details by ISBN in PHP”

  1. True, but for me it actually saved a bunch of time. Enter and ISBN and phpppptttt, out comes the information formatted the way I wanted it.

    Of course, I was actually smiling inside that I finally used my mad coding skillz for something useful. 😉

  2. Yeah, all of the following fields are available:

    • Title – The main title
    • TitleLong – The main title and the subtitle separated by a colon
    • AuthorsText – All authors, separated by a comma
    • PublisherText – The publisher
    • Summary – Not sure what this is, but it is available
    • Notes – Not sure what this is
    • UrlsText – Not sure what this is
    • AwardsText – Not sure what this is
    • Prices – A list of pricing information and stores

    They can be easily integrated into the script I put together. Have you gotten an API Key yet? If not, go get one then email me. I will walk you thought how to get this on your server to use it.

  3. People who find this may also be interested in this solution (code available for download) which does something similar to this, but also can Save to a pipe delimited text file (for easy importing into BookHound, for example). It also describes how you can use a relatively inexpensive bar code scanner for the ISBN number input.

    God bless the internets.

  4. Robert,
    I would be interested in talking to you through email regarding your “Getting books details by ISBN in PHP” and discussing ways to access more fields or developing a similar PHP script.

    Please email me so we can discuss.


  5. trivial to “protect” the input string.
    I changed your code to look like
    // convert to a number
    $isbn = intval(trim($_POST[‘isbn’]),10);
    // the standard says it must be 13 digits long if assigned after Jan 1, 2007.
    if (strlen($isbn) < 14) {
    * Get the result as a SimpleXML object
    $rs = simplexml_load_file("$apikey&index1=isbn&value1=$isbn&quot;);

    I think the above is enought to protect from any possible attacks.

  6. Hi Robert,

    Thanks for your guidance on getting the book details.I am trying to get all other available informations in the variable by extending your code as below ,but its not printing for some reason.Please advise.

    isbn; ?>*/
    Details; ?>
    language; ?>
    physical_description_text; ?>
    isbn; ?>


Leave a Reply

Your email address will not be published. Required fields are marked *