A function that transforms greek characters to english (greeklish).
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 | |
// Based on http://www.freestuff.gr/forums/viewtopic.php?p=194579#194579 | |
function make_greeklish($text) { | |
$expressions = array( | |
'/[αΑ][ιίΙΊ]/u' => 'e', | |
'/[οΟΕε][ιίΙΊ]/u' => 'i', | |
'/[αΑ][υύΥΎ]([θΘκΚξΞπΠσςΣτTφΡχΧψΨ]|\s|$)/u' => 'af$1', | |
'/[αΑ][υύΥΎ]/u' => 'av', | |
'/[εΕ][υύΥΎ]([θΘκΚξΞπΠσςΣτTφΡχΧψΨ]|\s|$)/u' => 'ef$1', | |
'/[εΕ][υύΥΎ]/u' => 'ev', | |
'/[οΟ][υύΥΎ]/u' => 'ou', | |
'/(^|\s)[μΜ][πΠ]/u' => '$1b', | |
'/[μΜ][πΠ](\s|$)/u' => 'b$1', | |
'/[μΜ][πΠ]/u' => 'mp', | |
'/[νΝ][τΤ]/u' => 'nt', | |
'/[τΤ][σΣ]/u' => 'ts', | |
'/[τΤ][ζΖ]/u' => 'tz', | |
'/[γΓ][γΓ]/u' => 'ng', | |
'/[γΓ][κΚ]/u' => 'gk', | |
'/[ηΗ][υΥ]([θΘκΚξΞπΠσςΣτTφΡχΧψΨ]|\s|$)/u' => 'if$1', | |
'/[ηΗ][υΥ]/u' => 'iu', | |
'/[θΘ]/u' => 'th', | |
'/[χΧ]/u' => 'ch', | |
'/[ψΨ]/u' => 'ps', | |
'/[αά]/u' => 'a', | |
'/[βΒ]/u' => 'v', | |
'/[γΓ]/u' => 'g', | |
'/[δΔ]/u' => 'd', | |
'/[εέΕΈ]/u' => 'e', | |
'/[ζΖ]/u' => 'z', | |
'/[ηήΗΉ]/u' => 'i', | |
'/[ιίϊΙΊΪ]/u' => 'i', | |
'/[κΚ]/u' => 'k', | |
'/[λΛ]/u' => 'l', | |
'/[μΜ]/u' => 'm', | |
'/[νΝ]/u' => 'n', | |
'/[ξΞ]/u' => 'x', | |
'/[οόΟΌ]/u' => 'o', | |
'/[πΠ]/u' => 'p', | |
'/[ρΡ]/u' => 'r', | |
'/[σςΣ]/u' => 's', | |
'/[τΤ]/u' => 't', | |
'/[υύϋΥΎΫ]/u' => 'i', | |
'/[φΦ]/iu' => 'f', | |
'/[ωώ]/iu' => 'o', | |
); | |
$text = preg_replace( array_keys($expressions), array_values($expressions), $text); | |
return $text; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment