Last active
February 15, 2023 23:42
-
-
Save dryks/c777d3ef1be8056cc46f732b131bed40 to your computer and use it in GitHub Desktop.
Транслитерация ссылок (урлов) с русского на английский transliterations url ru-eng PHP
This file contains 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 | |
define('LNGtranslit1','а,б,в,г,д,е,ё,ж,з,и,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,ы,ь,щ,ъ,э,ю,я'); | |
define('LNGtranslit2','a,b,v,g,d,e,yo,j,z,i,iy,k,l,m,n,o,p,r,s,t,u,f,h,c,ch,sh,y,,sh,,e,yu,ya'); | |
function translit($string,$max=60) { | |
$string=mb_strtolower($string,'UTF-8'); | |
$d1=explode(',',LNGtranslit1); | |
$d2=explode(',',LNGtranslit2); | |
$string=str_replace($d1,$d2,$string); | |
$d1=array(' ',',','&','і'); | |
$d2=array('-','-','-and-','i'); | |
$string=str_replace($d1,$d2,$string); | |
$string=preg_replace('|[^A-Za-z0-9\._+-]|','',$string); | |
if(strlen($string)>$max) $string=substr($string,0,$max); | |
return $string; | |
} | |
echo translit('Вася выпил пиво 5t'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks