fork download
  1. <?php
  2. function isGreekWord($word)
  3. {
  4. if (!preg_match_all('#(\p{Greek})#u', $word, $m))
  5. return false;
  6. $grTotal = count($m[0]);
  7. $enTotal = strlen(iconv('utf-8', 'iso8859-7', $word)) - $grTotal;
  8.  
  9. return $grTotal >= $enTotal;
  10. }
  11.  
  12. $en = array('a', 'e', 'k');
  13. $gr = array('α', 'ε', 'κ');
  14. $s = 'kaλημeρa κοσμe hεllo world γαλα'; // string from database
  15.  
  16. $tokens = explode(' ', $s);
  17. foreach($tokens as &$token) {
  18. if (isGreekWord($token))
  19. $token = str_replace($en, $gr, $token);
  20. else
  21. $token = str_replace($gr, $en, $token);
  22. }
  23. $s = implode(' ', $tokens);
  24. echo $s;
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
καλημερα κοσμε hello world γαλα