SHOW:
|
|
- or go back to the newest paste.
1 | class myTools | |
2 | { | |
3 | public static function stripText($text) | |
4 | { | |
5 | $text = mb_strtolower($text, 'utf-8'); | |
6 | ||
7 | // replace cyrillic chars | |
8 | $text = myTools::replaceCyrillic($text); | |
9 | ||
10 | // strip all non word chars | |
11 | $text = preg_replace('/\W/', ' ', $text); | |
12 | ||
13 | // replace all white space sections with a dash | |
14 | $text = preg_replace('/\ +/', '-', $text); | |
15 | ||
16 | // trim dashes | |
17 | $text = preg_replace('/\-$/', '', $text); | |
18 | $text = preg_replace('/^\-/', '', $text); | |
19 | ||
20 | return $text; | |
21 | } | |
22 | ||
23 | public static function replaceCyrillic ($text) | |
24 | { | |
25 | $chars = array( | |
26 | 'ґ'=>'g','ё'=>'e','є'=>'e','ї'=>'i','і'=>'i', | |
27 | 'а'=>'a', 'б'=>'b', 'в'=>'v', | |
28 | 'г'=>'g', 'д'=>'d', 'е'=>'e', 'ё'=>'e', | |
29 | - | 'ж'=>'zh', 'з'=>'z', 'и'=>'i', 'й'=>'i', |
29 | + | 'ж'=>'j', 'з'=>'z', 'и'=>'i', 'й'=>'i', |
30 | 'к'=>'k', 'л'=>'l', 'м'=>'m', 'н'=>'n', | |
31 | 'о'=>'o', 'п'=>'p', 'р'=>'r', 'с'=>'s', | |
32 | 'т'=>'t', 'у'=>'u', 'ф'=>'f', 'х'=>'h', | |
33 | 'ц'=>'c', 'ч'=>'ch', 'ш'=>'sh', 'щ'=>'sch', | |
34 | 'ы'=>'y', 'э'=>'e', 'ю'=>'u', 'я'=>'ya', 'é'=>'e', '&'=>'and', | |
35 | 'ь'=>'', 'ъ' => '', | |
36 | ); | |
37 | ||
38 | return strtr($text, $chars); | |
39 | } | |
40 | } |