Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = <<<END
- 0-413-72490-3
- 0-413-72490-5
- 0-9751194-0-0
- 1-56592-286-X
- 1234567890
- 123456789X
- 0123456789
- X123456789
- ---0-1-2-3-4-5-6-7-8-9---
- 0600.587495
- 052148342
- 05214834255
- #1&1+1,1;1:1|1>1.1$1
- END;
- $input = explode("\n", $input);
- $strip_values = array(',', '.', '/', "'", '<', '>', '?', ';', ':', '[', '{', ']', '}', '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '+', '=');
- //Who would do such a thing!!
- foreach($input as $key => $value){
- $uneditted_line = $value;
- $line = str_replace($strip_values, "", trim($value));
- $sum = 0;
- for($c = 1; $c < strlen($line); $c++){
- $sum += $line[$c-1]*$c;
- //echo $line[$c-1]."\n";
- }
- $check = $sum%11;
- if($check == 10){
- $check = 'X';
- }
- if($check == substr($line, -1)){
- print $uneditted_line." is a valid ISBN";
- }else{
- print $uneditted_line." is not a valid ISBN, the check character should be $check";
- }
- if($key != count($input)-1){
- print "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment