-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMisc.php
43 lines (37 loc) · 1.22 KB
/
Misc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class Misc
{
public static function isValidCredCard($string) {
// Strip any non-digits (useful for credit card numbers with spaces and hyphens)
$string=preg_replace('/\D/', '', $string);
// Set the string length and parity
$number_length=strlen($string);
$parity=$number_length % 2;
// Loop through each digit and do the maths
$total=0;
for ($i=0; $i<$number_length; $i++) {
$digit=$string[$i];
// Multiply alternate digits by two
if ($i % 2 == $parity) {
$digit*=2;
// If the sum is two digits, add them together (in effect)
if ($digit > 9) {
$digit-=9;
}
}
// Total up the digits
$total+=$digit;
}
// If the total mod 10 equals 0, the number is valid
return ($total % 10 == 0) ? TRUE : FALSE;
}
//Retorna o numero completando o tamanho com uma determinada qtde de zeros a esquerda
public static function strzero($valor, $zeros){
$zeros = $zeros - strlen("$valor");
$var = '0';
for($I=1; $I < $zeros; $I++){
$var = $var.'0';
}//fim for
return("$var$valor");
}
}