<?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 = ' ') {
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;
}
}