ClarkeRubber

UNSW ProgComp: Problem 3 - 2005

Jun 9th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. $input = <<<END
  4. 0-413-72490-3
  5. 0-413-72490-5
  6. 0-9751194-0-0
  7. 1-56592-286-X
  8. 1234567890
  9. 123456789X
  10. 0123456789
  11. X123456789
  12. ---0-1-2-3-4-5-6-7-8-9---
  13. 0600.587495
  14. 052148342
  15. 05214834255
  16. #1&1+1,1;1:1|1>1.1$1
  17. END;
  18.  
  19. $input = explode("\n", $input);
  20.  
  21. $strip_values = array(',', '.', '/', "'", '<', '>', '?', ';', ':', '[', '{', ']', '}', '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '+', '=');
  22. //Who would do such a thing!!
  23.  
  24. foreach($input as $key => $value){
  25.     $uneditted_line = $value;
  26.     $line = str_replace($strip_values, "", trim($value));
  27.  
  28.     $sum = 0;
  29.     for($c = 1; $c < strlen($line); $c++){
  30.         $sum += $line[$c-1]*$c;
  31.         //echo $line[$c-1]."\n";
  32.     }
  33.     $check = $sum%11;
  34.     if($check == 10){
  35.         $check = 'X';
  36.     }
  37.     if($check == substr($line, -1)){
  38.         print $uneditted_line." is a valid ISBN";
  39.     }else{
  40.         print $uneditted_line." is not a valid ISBN, the check character should be $check";
  41.     }
  42.  
  43.     if($key != count($input)-1){
  44.         print "\n";
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment