php class Methods public static function CreateHash count symbols ABCD

 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
class Methods {
public static function CreateHash($count) {
$symbols = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
$ret_val = "";
for ($i = 0; $i < $count; ++$i)
$ret_val .= $symbols[rand(0, 61)];
return $ret_val;
}
public static function SetSession($key, $value) {
$_SESSION[$key] = $value;
}
public static function RemoveSession($key) {
unset($_SESSION[$key]);
}
public static function SetCookie($name, $value, $remaining_time) {
setcookie($name, $value, $remaining_time, "/");
}
public static function RemoveCookie($name) {
setcookie($name, '', 0, "/");
}
public static function RusDeclension($root, $count) {
$endings = array("", "а", "ов");
$word = $root;
if ($count < 21) {
if ($count == 0) {
$word .= $endings[2];
} else if ($count == 1) {
$word .= $endings[0];
} else if ($count > 1 && $count < 5) {
$word .= $endings[1];
} else if ($count > 4 && $count < 21) {
$word .= $endings[2];
}
} else {
if ($count % 10 == 1) {
$word .= $endings[0];
} else if ($count % 10 > 1 && $count % 10 < 5) {
$word .= $endings[1];
} else {
$word .= $endings[2];
}
}
return $word;
}
public static function NumDelim($num, $delim = '&nbsp;') {
if ($num >= 1000) {
switch (rand(0, 2)) {
case 0:
//Developed by Alex
$delim = strrev($delim);
preg_match("/(\.\d+)*$/i", (string)$num, $modulo);
$str_num = preg_replace("/(\.\d+)*$/i", '', (string)$num);
return strrev(preg_replace("/(\d{3})/i", "$1{$delim}", strrev($str_num))).$modulo[0];
case 1:
//Developed by Andrey
$a = explode('.', $num);
$ans = '';
$len = strlen($a[0]);
$ans .= substr($a[0], 0, ($len % 3) ? $len % 3 : 3);
for ($i = ($len % 3) ? $len % 3 : 3; $i < $len; $i += 3) {
$ans .= $delim.substr($a[0], $i, 3);
}
$ans .= ($a[1]) ? '.'.$a[1] : '';
return $ans;
case 2:
//Developed by PHP developers xD
return preg_replace("/(\.|[0]){0,3}$/i", '', number_format($num, 2, '.', $delim));
}
}
return $num;
}
}