PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/aspell6-sr-0.02/misc/cyr2lat.php

#
PHP | 55 lines | 26 code | 11 blank | 18 comment | 2 complexity | a50b067103f4dbdbc3af98fc0589e16e MD5 | raw file
Possible License(s): LGPL-2.1
  1. #!/usr/local/bin/php
  2. <?php
  3. /*
  4. Author: Goran Rakic, 09/29/2005
  5. Known bug:
  6. This simple tool does not handle transliteration of capital
  7. Cyrillic characters that are written as two characters in Latin
  8. script correctly. For example, word "?????" should be converted
  9. to "NJEGOV" (this tool will do that correctly), but word "?????"
  10. should be converted to "Njegov" and script will convert it to
  11. "NJegov".
  12. You can find more robust solutions at URL:
  13. http://www.cirilica.org/programi.html
  14. */
  15. if (!function_exists('file_get_contents')) require_once('file_get_contents.php');
  16. if (!function_exists('file_put_contents')) require_once('file_put_contents.php');
  17. $small = array('?' => 'a', '?' => 'b', '?' => 'v', '?' => 'g', '?' => 'd',
  18. '?' => '?', '?' => 'e', '?' => 'ž', '?' => 'z', '?' => 'i',
  19. '?' => 'j', '?' => 'k', '?' => 'l', '?' => 'lj', '?' => 'm',
  20. '?' => 'n', '?' => 'nj', '?' => 'o', '?' => 'p', '?' => 'r',
  21. '?' => 's', '?' => 't', '?' => '?', '?' => '?', '?' => 'f',
  22. '?' => 'h', '?' => 'c', '?' => 'u', '?' => 'dž', '?' => 'š');
  23. $capital = array('?' => 'A', '?' => 'B', '?' => 'V', '?' => 'G', '?' => 'D',
  24. '?' => '?', '?' => 'E', '?' => 'Ž', '?' => 'Z', '?' => 'I',
  25. '?' => 'J', '?' => 'K', '?' => 'L', '?' => 'LJ', '?' => 'M',
  26. '?' => 'N', '?' => 'NJ', '?' => 'O', '?' => 'P', '?' => 'R',
  27. '?' => 'S', '?' => 'T', '?' => '?', '?' => '?', '?' => 'F',
  28. '?' => 'H', '?' => 'C', '?' => 'U', '?' => 'DŽ', '?' => 'Š');
  29. echo "\nSerbian Cyrillic to Serbian Latin transliteration tool\n\n";
  30. echo "Enter input filename: ";
  31. $in = trim(fgets(STDIN));
  32. echo "Enter output filename: ";
  33. $out = trim(fgets(STDIN));
  34. $input = file_get_contents($in);
  35. $rep = array_merge($small, $capital);
  36. $output = strtr($input, $rep);
  37. file_put_contents($out, $output);
  38. echo "Done.\n";
  39. ?>