Miscellaneous Code

  Home arrow Miscellaneous Code arrow Book Information Lookup Via ISBN
MISCELLANEOUS CODE

Book Information Lookup Via ISBN
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2004-01-07

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    This function when passed a valid ISBN number will attempt to locate the title, authors, publisher, edition and volume from Powell's Books website. I'm sure this could be refined a bit but it worked for a purpose.

    By : rellik

    <?php
    // This script looks up a user entered ISBN number on Powells Books to pull the
    // book record from to save the users time and us errors.

    // The ISBN number will be passed to us via the variable isbn through http post

    function isbn($isbn) {

    if(!empty($isbn)) {
    $title = $author1 = $author2 = $author3 = $publisher = $edition = $volume = $price = $coursenumber = $coursename = "";

    $findarecord = mysql_query("SELECT * FROM books WHERE isbn='$isbn'");
    while ($info = mysql_fetch_array($findarecord)) {
    if(empty($title)) {
    $title = $info["title"];
    }
    if(empty($author1)) {
    $author1 = $info["author1"];
    }
    if(empty($author2)) {
    $author2 = $info["author2"];
    }
    if(empty($author3)) {
    $author3 = $info["author3"];
    }
    if(empty($publisher)) {
    $publisher = $info["publisher"];
    }
    if(empty($edition)) {
    $edition = $info["edition"];
    }
    if(empty($volume)) {
    $volume = $info["volume"];
    }
    if(empty($price)) {
    $price = $info["price"];
    }
    if(empty($coursenumber)) {
    $coursenumber = $info["coursenumber"];
    }
    if(empty($coursename)) {
    $coursename = $info["coursename"];
    }
    }

    if(empty($title) || empty($author1) || empty($publisher) || empty($price) || empty($coursenumber) || empty($coursename)) {

    $lookuphost = "www.powells.com";
    $lookuphosturl = "/cgi-bin/biblio?inkey=1-$isbn";
    $fp = fsockopen($lookuphost, 80);
    $buf = "";
    fputs($fp, "GET $lookuphosturl HTTP/1.0\r\n Host: $lookuphost\r\n\r\n");
    while(!feof($fp)) {
    $buf .= fgets($fp,1000000);
    }
    fclose($fp);
    if(empty($title)) {
    @$title = trim(strip_tags(substr($buf,strpos($buf,"<!-- BEGIN BASIC INFO -->")+111,90)));
    if(ereg(" by",$title)) {
    $title = trim(substr($title,0,strlen($title)-5));
    }
    }
    if(empty($publisher)) {
    @$publisher = trim(strip_tags(substr($buf,strpos($buf,"<B>Publisher:</B>")+17,100)));
    @$publisher = trim(substr($publisher,0,strpos($publisher,"Subject:")));
    }
    if(empty($edition)) {
    @$editionraw = trim(strip_tags(substr($buf,strpos($buf,"<B>Edition Number:</B>")+22,4)));
    @$null = ereg("([0-999])",$editionraw,$editionnum);
    $edition = $editionnum[0];
    }
    @$authorsraw = trim(substr($buf,strpos($buf,"<B>Author:</B>")+14,250));
    if(empty($author1)) {
    @$author1 = trim(substr($authorsraw,0,strpos($authorsraw,"<B>Author:</B>")));
    }
    if(empty($author2)) {
    @$author2 = trim(substr($authorsraw,strpos($authorsraw,$author1)+strlen($author1)+15,100));
    @$author2 = trim(strip_tags(substr($author2,0,strpos($author2,"Publisher"))));
    }

    // Clean up vars
    $title = stripslashes(str_replace("&nbsp;","",trim($title)));
    $author1 = stripslashes(str_replace("&nbsp;","",trim($author1)));
    if(strlen($author1)<=1) {
    $author1="";
    }
    $author2 = stripslashes(str_replace("&nbsp;","",trim($author2)));
    if(strlen($author2)<=1) {
    $author2="";
    }
    $author3 = stripslashes(str_replace("&nbsp;","",trim($author3)));
    if(strlen($author3)<=1) {
    $author3="";
    }
    $publisher = stripslashes(str_replace("&nbsp;","",trim($publisher)));
    $edition = trim($edition);
    $volume = trim($volume);
    }

    if(empty($title)) {
    $title = "";
    $author1 = "";
    $author2 = "";
    $author3 = "";
    $publisher = "";
    $volume = "";
    $edition = "";
    $price = "";
    $coursenumber = "";
    $coursesection = "";
    $coursename = "";
    }
    return array("isbn"=>$isbn,"title"=>$title,"author1"=>$author1,"author2"=>$author2,"author3"=>$author3,"publisher"=>$publisher,"edition"=>$edition,"volume"=>$volume,"price"=>$price,"condition"=>"0","coursenumber"=>$coursenumber,"coursesection"=>"","coursename"=>$coursename);
    }
    }
    ?>

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap