home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / php.exe / Check ISBN.php < prev    next >
Encoding:
PHP Script  |  2001-07-03  |  1.2 KB  |  32 lines

  1. //**************************************
  2.     //     
  3.     // Name: Check ISBN
  4.     // Description:Checks an entered isbn (w
  5.     //     ith or without hyphens) to see if it is 
  6.     //     valid. by Keith Nunn
  7.     // By: PHP Code Exchange
  8.     //**************************************
  9.     //     
  10.     
  11.     <?php
  12.         /*
  13.          *    Check to see if the entered isbn is valid and return
  14.          *    true or false depending.
  15.          *    I'm not even going to try to claim copyright for such 
  16.          *    a simple thing. Do what you will with it. 
  17.          *    8-) Keith Nunn, kapn@anglican.ca
  18.          */
  19.         function checkisbn($isbn) {
  20.             $isbn10 = ereg_replace("[^0-9X]","",$isbn);
  21.             $checkdigit = 11 - ( ( 10 * substr($isbn10,0,1) + 9 * substr($isbn10,1,1) + 8 * substr($isbn10,2,1) + 7 * substr($isbn10,3,1) + 6 * substr($isbn10,4,1) + 5 * substr($isbn10,5,1) + 4 * substr($isbn10,6,1) + 3 * substr($isbn10,7,1) + 2 * substr($isbn10,8,1) ) % 11);
  22.             if ( $checkdigit == 10 ) $checkdigit = "X";
  23.             if ( $checkdigit == 11 ) $checkdigit = 0;
  24.             if ( $checkdigit == substr($isbn10,9,1) ) {
  25.                 return true;
  26.             } else {
  27.                 return false;
  28.             }
  29.         }
  30.     ?>
  31.  
  32.