Created
December 12, 2024 12:04
-
-
Save arterm-sedov/2219fe01aaacb964cdead7dc843a5af0 to your computer and use it in GitHub Desktop.
PHP code to convert Russian letters to Latin lower case letters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function transliterate_to_lower($string) | |
| { | |
| $cyr = ['а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п', 'р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я']; | |
| $lat = ['a','b','v','g','d','e','e','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f','h','c','ch','sh','sh','','y','','e','yu','ya']; | |
| $strlat = str_replace($cyr, $lat, mb_strtolower($string)); | |
| return $strlat; | |
| } | |
| echo transliterate_to_lower("Привет, 1-й ёжик!"); | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Input: Привет, 1-й ёжик!
Output: privet, 1-j ezhik!
This code may be useful to preprocess Russian strings for slugification, e.g. in URLs.
It is based on GOST R 7.0.34-2014 with the following exceptions:
ё=e(instead ofyo)щ=sh(instead ofshh)ъ— omittedь— omittedIt works very differently from
transliterator_transliterate()where:ж=zч=cш=sщ=sЪ=``Ь=`ю=uя=aAs a result,
transliterator_transliterate()does not follow the typical Russian transliteration rules.