Skip to content

Instantly share code, notes, and snippets.

@teomaragakis
Last active August 3, 2022 14:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teomaragakis/7580134 to your computer and use it in GitHub Desktop.
Save teomaragakis/7580134 to your computer and use it in GitHub Desktop.
A function that transforms greek characters to english (greeklish).
<?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;
}
?>
@tivuno
Copy link

tivuno commented Aug 3, 2022

@teomaragakis σ έχει ξεφύγει το ΐ πχ αν κάνεις μετατροπή Παΐσιος => paΐsios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment