-
Notifications
You must be signed in to change notification settings - Fork 2
/
String.php
71 lines (56 loc) · 1.93 KB
/
String.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
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
<?php
/**
* Класс для работы с текстом в UTF-8 кодировке
*
*/
abstract class System_String {
private final function __construct() {}
/**
* Перевод в нижний регистр
*
* @param string $string
* @return string
*/
public static function StrToLower($string) {
return mb_strtolower($string, "UTF-8");
}
/**
* Перевод в верхний регистр
*
* @param string $string
* @return string
*/
public static function StrToUpper($string) {
return mb_strtoupper($string, "UTF-8");
}
/**
* Транслитерация
*
* @param string $string
* @return string
*/
public static function Translit($string) {
$replace = array ("а" => "a", "б" => "b", "в" => "v", "г" => "g", "д" => "d", "е" => "e", "ж" => "zh",
"з" => "z", "и" => "i", "й" => "y", "к" => "k", "л" => "l", "м" => "m",
"н" => "n", "о" => "o", "п" => "p", "р" => "r", "с" => "s", "т" => "t",
"у" => "u", "ф" => "f", "х" => "h", "ц" => "ts", "ч" => "ch", "ш" => "sh",
"щ" => "sch", "ъ" => "'", "ы" => "yi", "ь" => "", "э" => "e", "ю" => "yu", "я" => "ya" );
return iconv("UTF-8", "UTF-8//IGNORE", strtr($string, $replace));
}
/**
* Транслитерация из латиницы в кирилицу
*
* @param string $string
* @return string
*/
public static function TranslitReverse($string) {
$replace = array("a" => "а", "b" => "б", "v" => "в", "g" => "г", "d" => "д",
"e" => "е", "j" => "ж", "z" => "з", "i" => "и", "y" => "й", "k" => "к",
"l" => "л", "m" => "м", "n" => "н", "o" => "о", "p" => "п", "r" => "р", "w" => "в",
"s" => "с", "t" => "т", "u" => "у", "f" => "ф", "h" => "х", "c" => "ц", "q" => "к");
return iconv("UTF-8", "UTF-8//IGNORE", strtr($string, $replace));
}
public static function Substr($string, $start, $length = null) {
return mb_substr($string, $start, $length, "UTF-8");
}
}