Zend Framework Source Code Snippets

Action helper Translite

Bookmark and Share
1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
29
3031
32
33
34
3536
37
38
39
4041
42
43
44
45
<?php
/**
 * @copyright  2008, IgorN
 * @author     IgorN (progi2007@gmail.com)
 */class Application_Helper_Action_Translite extends Zend_Controller_Action_Helper_Abstract {
        
        public function translite( $input )
        {
                $arrRus = array( 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м',                                    'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь',
                                    'ы', 'ъ', 'э', 'ю', 'я',
                                    'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М',
                                    'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ь',
                                    'Ы', 'Ъ', 'Э', 'Ю', 'Я' );                $arrEng = array( 'a', 'b', 'v', 'g', 'd', 'e', 'jo', 'zh', 'z', 'i', 'y', 'k', 'l', 'm',
                                    'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'kh', 'c', 'ch', 'sh', 'sch', 'mb',
                                    'y', 'bm', 'e', 'ju', 'ja',
                                    'A', 'B', 'V', 'G', 'D', 'E', 'JO', 'ZH', 'Z', 'I', 'Y', 'K', 'L', 'M',
                                    'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'KH', 'C', 'CH', 'SH', 'SCH', 'MB',                                    'Y', 'BM', 'E', 'JU', 'JA' );
                 return str_replace($arrRus, $arrEng, $input);
        }
        public function transliteUrl ( $url )
        {                       $arrRus = array( 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м',
                                    'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь',
                                    'ы', 'ъ', 'э', 'ю', 'я',
                                    'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М',
                                    'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ь',                                    'Ы', 'Ъ', 'Э', 'Ю', 'Я' );
                $arrEng = array( 'a', 'b', 'v', 'g', 'd', 'e', 'jo', 'zh', 'z', 'i', 'y', 'k', 'l', 'm',
                                    'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'kh', 'c', 'ch', 'sh', 'sch', 'mb',
                                    'y', 'bm', 'e', 'ju', 'ja',
                                    'A', 'B', 'V', 'G', 'D', 'E', 'JO', 'ZH', 'Z', 'I', 'Y', 'K', 'L', 'M',                                    'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'KH', 'C', 'CH', 'SH', 'SCH', 'MB',
                                    'Y', 'BM', 'E', 'JU', 'JA' );
                 $url = str_replace($arrRus, $arrEng, $url);
                 $url = trim( $url );
                 $url = preg_replace("/[^-a-z0-9~s.:;+=_/]/i", '', strtolower( $url ));                 $url = preg_replace("/[s.:;=+]+/i", '-', $url);
                 return $url;
        }
}
?>

Comments

You must login before commenting on a snippet. If you do not have an account, please register.

Snippet description

Snippet details

Created:
IgorN IgorN
2 years ago
Edited:
IgorN IgorN
2 years ago
Revision Id:
94
Edit Message:
Initial Release
Tags:
translite
Comments:
0
Views:
770
Points:
0 (0 votes)

History

r94

Initial Release

IgorN IgorN
2 years ago
diff
r20

Initial Release

IgorN IgorN
2 years ago