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 ISBNdb.com 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 ISBNdb.com 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.
<?php /** * 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 */ if ($_SERVER['REQUEST_METHOD'] == 'POST') { /** * 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 * THIS AS IS AT YOUR OWN PERIL. */ $isbn = $_POST['isbn']; /** * Get the result as a SimpleXML object */ $rs = simplexml_load_file("http://isbndb.com/api/books.xml?access_key=$apikey&index1=isbn&value1=$isbn"); } ?> <html> <head><title>ISBN Check</title></head> <body> <form method="post" action="<?php echo basename(__FILE__) ?>"> <p> Enter an ISBN:<br /> <input type="text" size="40" name="isbn" id="isbn" value="<?php echo $isbn ?>" /> </p> <p> <input type="submit" name="submit" value="Search ISBN" /> </p> </form> <?php /** * Only output more stuff if there is a result */ if ($rs) : ?> <hr /> Results for ISBN: <?php echo $isbn ?>: <?php /** * Results for a book are in $rs->BookList->BookData * * You can see this using var_dump($rs); */ $book = $rs->BookList->BookData; ?> <p> <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; ?> </p> <?php endif; ?> </body> </html>
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.
0316116955
I hope you enjoy this, if you happen to be looking for an ISBN search tool that you can run on your own.
Microsoft Expression Web Super Preview
I just read an article on ZDNet that mentioned a recent "showing off" of Expression Web SuperPreview by Microsoft. SuperPreview allows web developers to view and debug web output and rendering as it would appear in Internet Explorer 6, 7 and 8. And I can't help but wonder... why would we need a tool to check rendering if Microsoft actually handled rendering properly to begin with?
I am glad they have introduced this tool. Before this you had to install an application that would literally install multiple versions of IE on your machine. Then you would need to load your page in a new instance of whatever version you wanted to test. That really sucked. So having the option to inspect your rendering in one app across multiple versions of IE is definitely a boon. But still, why should you have to do that?
And speaking of browsers, a friend of mine the a few weeks back brought up a point that I still enjoy... why are we still coding for browser based output anyway? The web as we know it is totally breaking out of the browser. Why are there still cross-browser compatibility issues and rendering problems?
While I applaud Microsoft on their efforts to help developers code for their broken, crappy, waste-of-software browser, I think I am leaning more towards my friend's way of thinking. Maybe it is time to start thinking outside the browser box?
Regardless, if you are a developer developing on Windows and you need a tool that will help you see how things are going to work for you in IE 6, 7 and 8, this might be the tool for you.
Fun with PHP
Every now and again someone writes a line or two of code that really makes me smile. Such is the case with this outcome determinating and decision making class below. This code is being reproduced, with or without consent, from the PHP Developers Network's own scottayy.
<?php /** * Coin flipper class helps determine outcome of situations in which an outcome * cannot be decided by sheer manpower alone. * * @author Scott Martin <scottayy@devnetwork.net> * @license None, don't even try to use this or your hair will turn yellow */ class coin { /** * The outcome determinators * * Each invocation of this object will require a determinator upon which the * object relies to build a determined outcome. These are those determinators. * * @access private * @var array */ private static $_sides = array('heads', 'tails'); /** * The determinating method * * This method, when called, invokes a determination sequence and returns a * determined value for use in decision making. * * @access public * @return string Randomly selected determinator */ public static function flip() { // Quick, randomize me some determinators shuffle(self::$_sides); // Quick, offer it back before it gets angry return self::$_sides[mt_rand(0, 1)]; } } /** * We should always test our determinating decision establisher * * 2,4,6,8 You know you want to determinate */ echo coin::flip(); ?>
For those that just have to have an object to instantiate (and you know who you are), there is this lightly modified version for your obsessive/compulsive selves:
<?php /** * Coin flipper class helps determine outcome of situations in which an outcome * cannot be decided by shear manpower alone. * * @author Scott Martin <scottayy@devnetwork.net> * @license None, don't even try to use this or your hair will turn yellow */ class coin { /** * The outcome determinators * * Each invocation of this object will require a determinator upon which the * object relies to build a determined outcome. These are those determinators. * * @access private * @var array */ private $_sides = array('heads', 'tails'); /** * The determinating method * * This method, when called, invokes a determination sequence and returns a * determined value for use in decision making. * * @access public * @return string Randomly selected determinator */ public function flip() { // Quick, randomize me some determinators shuffle($this->_sides); // Quick, offer it back before it gets angry return $this->_sides[mt_rand(0, 1)]; } } /** * We should always test our determinating decision establisher */ $coin = new coin; /** * 2,4,6,8 You know you want to determinate */ echo $coin->flip(); ?>
See, just looking at that code makes you want to smile doesn't it? Geeks are great.
A bit of irony in the PHP world
According to an article today by TechCrunch, Zend Technologies, The PHP company, is cutting 25% of their PHP developer staff, perhaps with an eye towards selling the company.
Israeli startup Zend Technologies has fired 25 percent of its R&D team (at least ten people), as well as others across the company, in an attempt to become cash flow positive, says a source close to the company. A spokesperson from the company’s PR firm says: “Yes, I can confirm that Zend made the layoffs, but we cannot comment on the numbers or reasons for the action.”
Read the complete TechCrunch article here.
As I read the brief article I began to think that this is not really anything that should be too newsworthy. Many companies in the USA, and around the world in general, are feeling the pinch of a down economy. Companies have to do what they can to reduce cost while maintaining competitive prices for goods and services. What Zend is doing is not really that out of the ordinary.
And I am not sure that Zend, as a company, is really worth a huge amount of money like the Sun Microsystems acquisition of MySQL was. It might be tasty to some of the players in the industry right now like Oracle, IBM or even a Sun. But really, other than the Zend engine and the Zend IDE what exactly does Zend have to offer?
Whatever happens to Zend from all of this one thing is very important to remember. Many a PHP developer now has the opportunity to seek gainful employment from other companies that are seeking, heavily, PHP talent. Many Silicon Valley companies, including many companies in the social networking space, are looking for top tier PHP talent right now. Companies like Ning, Digg, Facebook, Technorati, Yahoo and Google are constantly hiring PHP developers.
Times are good for being a PHP developer. Maybe not so much if you worked for Zend. Nonetheless, now is a great time to know a great deal about PHP.