How do you create a function of translating Russian letters into translites?
-
How can a function be created that replaces Russian letters in English (translite)?
For example, nameАртур
INPUT
<?php function func() { // } $text='Артур'; echo func($text); ?>
OUTPUT
Artur
And the letters.
ч, щ, э, ъ, ю, и, й, ц, с
How can you be replaced correctly in English?
-
You need a function.
str_replace();
function convertRUcharacters($str) { $from = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я','А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я'); $to = array('a','b','v','g','d','e','e','zh','z','i','i','k','l','m','n','o','p','r','s','t','u','f','kh','cz','ch','sh','shh','','y','','e','yu','ya','A','B','V','G','D','E','E','ZH','Z','I','I','K','L','M','N','O','P','R','S','T','U','F','KH','CZ','CH','SH','SHH','','Y','','E','YU','YA'); return str_replace($from, $to, $str); } echo convertRUcharacters('Артур');
But be careful with the coding. UTF8, WIN1251, etc. Functions with multibite lines may be required ( http://php.net/manual/ru/ref.mbstring.php )