commit | author | age
|
175a52
|
1 |
<?php |
JK |
2 |
class checksum { |
|
3 |
static function EAN($kod) { |
|
4 |
$kod = str_split($kod); |
|
5 |
|
|
6 |
$now = 1; |
|
7 |
foreach($kod as $v) { |
|
8 |
if($now==1) { |
|
9 |
$sum += $v; |
|
10 |
$now = 3; |
|
11 |
} |
|
12 |
else |
|
13 |
{ |
|
14 |
$sum += $v*3; |
|
15 |
$now = 1; |
|
16 |
} |
|
17 |
} |
|
18 |
|
|
19 |
return (10 - ($sum%10)) % 10; |
|
20 |
} |
|
21 |
|
|
22 |
static function ISBN($kod) { |
|
23 |
$kod = str_split($kod); |
|
24 |
|
|
25 |
foreach($kod as $k => $v) { |
|
26 |
$sum += (10-$k)*$v; |
|
27 |
} |
|
28 |
|
|
29 |
$sum = (11 - ($sum % 11)) % 11; |
|
30 |
if($sum == 10) { |
|
31 |
$sum = 'X'; |
|
32 |
} |
|
33 |
|
|
34 |
return $sum; |
|
35 |
} |
|
36 |
|
|
37 |
static function ISSN($kod) { |
|
38 |
$kod = str_split($kod); |
|
39 |
|
|
40 |
foreach($kod as $k => $v) { |
|
41 |
$sum += (8-$k)*$v; |
|
42 |
} |
|
43 |
|
|
44 |
$sum = (11 - ($sum % 11)) % 11; |
|
45 |
if($sum == 10) { |
|
46 |
$sum = 'X'; |
|
47 |
} |
|
48 |
|
|
49 |
return $sum; |
|
50 |
} |
|
51 |
} |
|
52 |
?>
|