v 0. Pasted by provocateur as php at 2008-07-10 18:30:30 MSK and set expiration to never.
v 1. Edited by null as php at 2008-07-12 18:48:22 MSK and set expiration to never.
v 2. Edited by null as php at 2008-07-12 18:51:50 MSK and set expiration to never.
v 3. Edited by Anonymous as php at 2009-02-24 10:22:09 MSK and set expiration to never.
v 4. Edited by null as php at 2009-06-13 21:18:11 MSK and set expiration to never.
v 5. Edited by mxmt as php at 2009-06-13 21:45:10 MSK and set expiration to 2009-06-16 21:45:10 MSK.
v 5. Reverted by 5668 to version 0 at 2009-09-29 01:00:57 MSK.
v 6. Reverted by Anonymous to version 0 at 2009-11-10 19:35:06 MSK.
v 7. Reverted by Anonymous to version 0 at 2009-11-10 19:35:41 MSK.
v 8. Reverted by null to version 0 at 2009-11-25 00:02:56 MSK.
v 9. Reverted by null to version 0 at 2009-11-25 00:03:28 MSK.
v 10. Reverted by Anonymous to version 0 at 2010-02-09 20:25:51 MSK.
v 11. Edited by Anonymous as php at 2010-04-16 00:12:19 MSK and set expiration to never.
v 12. Reverted by Anonymous to version 0 at 2010-04-16 00:12:41 MSK.
v 13. Edited by Anonymous as php at 2010-04-20 05:03:41 MSK and set expiration to never.
v 14. Reverted by Anonymous to version 0 at 2010-05-14 13:59:20 MSK.
v 15. Reverted by Anonymous to version 1 at 2010-05-14 14:04:12 MSK.
v 16. Reverted by Anonymous to version 0 at 2010-06-27 03:50:10 MSK.
v 17. Edited by AGvin as php at 2010-07-29 14:24:07 MSK and set expiration to never.
v 18. Edited by vkontakte.ria.ua/agvinria as php at 2010-07-29 14:30:47 MSK and set expiration to never.
v 19. Edited by AGvin vkontakte.ru/agvinria as php at 2010-07-29 14:32:26 MSK and set expiration to never.
v 20. Edited by AGvin vkontakte.ru/agvin as php at 2010-07-29 14:33:08 MSK and set expiration to never.
v 21. Edited by Anonymous as php at 2010-10-15 09:00:46 MSK and set expiration to never.
v 22. Edited by Anonymous as php at 2011-03-06 23:42:14 MSK and set expiration to never.
v 23. Edited by ann as php at 2011-04-21 12:21:05 MSK and set expiration to never.
v 24. Reverted by Anonymous to version 0 at 2011-04-21 17:29:50 MSK.
v 25. Reverted by Anonymous to version 0 at 2011-09-13 16:17:31 MSK.
v 26. Reverted by Anonymous to version 24 at 2011-09-13 16:17:58 MSK.
v 27. Reverted by Anonymous to version 0 at 2011-10-09 19:09:51 MSK.
v 28. Edited by Anonymous as php at 2011-10-25 15:55:09 MSK and set expiration to never.
v 29. Edited by karma as php at 2011-10-25 16:38:09 MSK and set expiration to never.
v 30. Reverted by Anonymous to version 0 at 2012-03-15 19:35:56 MSK.
v 31. Reverted by Anonymous to version 29 at 2012-03-19 08:49:30 MSK.
v 32. Edited by jtibmyanoe as c at 2013-02-14 16:56:09 MSK and set expiration to 2013-02-14 17:56:09 MSK.
v 32. Edited by qdfrgfnwgw as c at 2013-02-15 01:31:14 MSK and set expiration to 2013-02-15 02:31:14 MSK.
v 32. Edited by yptkvfcpot as c at 2013-02-16 02:57:35 MSK and set expiration to 2013-02-16 03:57:35 MSK.
v 32. Edited by kjdilflpbv as c at 2013-02-19 19:27:39 MSK and set expiration to 2013-02-19 20:27:39 MSK.
v 32. Edited by jukdobjcoy as c at 2013-02-20 02:25:15 MSK and set expiration to 2013-02-20 03:25:15 MSK.
v 32. Edited by depremtnqy as c at 2013-02-20 09:19:58 MSK and set expiration to 2013-02-20 10:19:58 MSK.
v 32. Edited by 1 as asm at 2014-07-12 10:20:08 MSK and set expiration to 2014-07-12 11:20:08 MSK.
v 33. Edited by 1 as -1' at 2014-07-12 10:20:10 MSK and set expiration to 2014-07-12 11:20:10 MSK.
v 34. Edited by 1 as asm at 2014-07-12 10:20:12 MSK and set expiration to 2014-07-12 09:20:12 MSK.
v 35. Edited by 1 as asm at 2014-07-12 10:20:14 MSK and set expiration to 2014-07-12 11:20:14 MSK.
v 36. Edited by 1 as asm at 2014-07-12 10:20:18 MSK and set expiration to 2014-07-12 11:20:18 MSK.
v 37. Edited by -1' as asm at 2014-07-12 10:20:20 MSK and set expiration to 2014-07-12 11:20:20 MSK.
v 32. Edited by 1 as c at 2014-08-20 11:15:50 MSK and set expiration to 2014-08-20 12:15:50 MSK.
v 33. Edited by 1 as -1' at 2014-08-20 11:15:52 MSK and set expiration to 2014-08-20 12:15:52 MSK.
v 34. Edited by 1 as c at 2014-08-20 11:15:53 MSK and set expiration to 2014-08-20 10:15:53 MSK.
v 35. Edited by 1 as c at 2014-08-20 11:15:55 MSK and set expiration to 2014-08-20 12:15:55 MSK.
v 36. Edited by 1 as c at 2014-08-20 11:15:59 MSK and set expiration to 2014-08-20 12:15:59 MSK.
v 37. Edited by -1' as c at 2014-08-20 11:16:01 MSK and set expiration to 2014-08-20 12:16:01 MSK.
v 32. Edited by 1 as -1' at 2014-11-17 00:18:28 MSK and set expiration to 2014-11-17 01:18:28 MSK.
v 33. Edited by 1 as asm at 2014-11-17 00:18:29 MSK and set expiration to 2014-11-16 23:18:29 MSK.
v 34. Edited by 1 as asm at 2014-11-17 00:18:30 MSK and set expiration to 2014-11-17 01:18:30 MSK.
v 35. Edited by 1 as asm at 2014-11-17 00:18:33 MSK and set expiration to 2014-11-17 01:18:33 MSK.
v 36. Edited by -1' as asm at 2014-11-17 00:18:34 MSK and set expiration to 2014-11-17 01:18:34 MSK.
v 32. Edited by -1' as c at 2014-12-03 21:15:34 MSK and set expiration to 2014-12-03 22:15:34 MSK.
v 32. Edited by -1' as asm at 2015-02-14 02:30:58 MSK and set expiration to 2015-02-14 03:30:58 MSK.
v 32. Reverted by Anonymous to version 0 at 2015-03-26 16:22:04 MSK.

Paste will expire never.

  1. <?php
  2.  
  3. //------------------------------------------------------------------------------
  4.  
  5. function dmword($string, $is_cyrillic = true)
  6. {   
  7.     static $codes = array(
  8.         'A' =>  array(array(0, -1, -1),
  9.             'I' =>  array(array(0, 1, -1)),
  10.             'J' =>  array(array(0, 1, -1)),
  11.             'Y' =>  array(array(0, 1, -1)),
  12.             'U' =>  array(array(0, 7, -1))),
  13.        
  14.         'B' =>  array(array(7, 7, 7)),
  15.        
  16.         'C' =>  array(array(5, 5, 5), array(4, 4, 4),
  17.             'Z' =>  array(array(4, 4, 4),
  18.                 'S' =>  array(array(4, 4, 4))),
  19.             'S' =>  array(array(4, 4, 4),
  20.                 'Z' =>  array(array(4, 4, 4))),
  21.             'K' =>  array(array(5, 5, 5), array(45, 45, 45)),
  22.             'H' =>  array(array(5, 5, 5), array(4, 4, 4),
  23.                 'S' =>  array(array(5, 54, 54)))),
  24.                
  25.         'D' =>  array(array(3, 3, 3),
  26.             'T' =>  array(array(3, 3, 3)),
  27.             'Z' =>  array(array(4, 4, 4),
  28.                 'H' =>  array(array(4, 4, 4)),
  29.                 'S' =>  array(array(4, 4, 4))),
  30.             'S' =>  array(array(4, 4, 4),
  31.                 'H' =>  array(array(4, 4, 4)),
  32.                 'Z' =>  array(array(4, 4, 4))),
  33.             'R' =>  array(
  34.                 'S' =>  array(array(4, 4, 4)),
  35.                 'Z' =>  array(array(4, 4, 4)))),
  36.  
  37.         'E' =>  array(array(0, -1, -1),
  38.             'I' =>  array(array(0, 1, -1)),
  39.             'J' =>  array(array(0, 1, -1)),
  40.             'Y' =>  array(array(0, 1, -1)),
  41.             'U' =>  array(array(1, 1, -1))),
  42.            
  43.         'F' =>  array(array(7, 7, 7),
  44.             'B' =>  array(array(7, 7, 7))),
  45.            
  46.         'G' =>  array(array(5, 5, 5)),
  47.        
  48.         'H' =>  array(array(5, 5, -1)),
  49.        
  50.         'I' =>  array(array(0, -1, -1),
  51.             'A' =>  array(array(1, -1, -1)),
  52.             'E' =>  array(array(1, -1, -1)),
  53.             'O' =>  array(array(1, -1, -1)),
  54.             'U' =>  array(array(1, -1, -1))),
  55.            
  56.         'J' =>  array(array(4, 4, 4)),
  57.        
  58.         'K' =>  array(array(5, 5, 5),
  59.             'H' =>  array(array(5, 5, 5)),
  60.             'S' =>  array(array(5, 54, 54))),
  61.            
  62.         'L' =>  array(array(8, 8, 8)),
  63.        
  64.         'M' =>  array(array(6, 6, 6),
  65.             'N' =>  array(array(66, 66, 66))),
  66.        
  67.         'N' =>  array(array(6, 6, 6),
  68.             'M' =>  array(array(66, 66, 66))),
  69.        
  70.         'O' =>  array(array(0, -1, -1),
  71.             'I' =>  array(array(0, 1, -1)),
  72.             'J' =>  array(array(0, 1, -1)),
  73.             'Y' =>  array(array(0, 1, -1))),
  74.            
  75.         'P' =>  array(array(7, 7, 7),
  76.             'F' =>  array(array(7, 7, 7)),
  77.             'H' =>  array(array(7, 7, 7))),
  78.            
  79.         'Q' =>  array(array(5, 5, 5)),
  80.        
  81.         'R' =>  array(array(9, 9, 9),
  82.             'Z' =>  array(array(94, 94, 94), array(94, 94, 94)), // special case
  83.             'S' =>  array(array(94, 94, 94), array(94, 94, 94))), // special case
  84.            
  85.         'S' =>  array(array(4, 4, 4),
  86.             'Z' =>  array(array(4, 4, 4),
  87.                 'T' =>  array(array(2, 43, 43)),
  88.                 'C' =>  array(
  89.                     'Z' => array(array(2, 4, 4)),
  90.                     'S' => array(array(2, 4, 4))),
  91.                 'D' =>  array(array(2, 43, 43))),
  92.             'D' =>  array(array(2, 43, 43)),
  93.             'T' =>  array(array(2, 43, 43),
  94.                 'R' =>  array(
  95.                     'Z' =>  array(array(2, 4, 4)),
  96.                     'S' =>  array(array(2, 4, 4))),
  97.                 'C' =>  array(
  98.                     'H' =>  array(array(2, 4, 4))),
  99.                 'S' =>  array(
  100.                     'H' =>  array(array(2, 4, 4)),
  101.                     'C' =>  array(
  102.                         'H' =>  array(array(2, 4, 4))))),
  103.             'C' =>  array(array(2, 4, 4),
  104.                 'H' =>  array(array(4, 4, 4),
  105.                     'T' => array(array(2, 43, 43),
  106.                         'S' => array(
  107.                             'C' => array(
  108.                                 'H' =>  array(array(2, 4, 4))),
  109.                             'H' => array(array(2, 4, 4))),
  110.                         'C' => array(
  111.                             'H' =>  array(array(2, 4, 4)))),
  112.                     'D' =>  array(array(2, 43, 43)))),
  113.             'H' =>  array(array(4, 4, 4),
  114.                 'T' =>  array(array(2, 43, 43),
  115.                     'C' =>  array(
  116.                         'H' =>  array(array(2, 4, 4))),
  117.                     'S' =>  array(
  118.                         'H' =>  array(array(2, 4, 4)))),
  119.                 'C' =>  array(
  120.                     'H' =>  array(array(2, 4, 4))),
  121.                 'D' =>  array(array(2, 43, 43)))),
  122.                
  123.         'T' =>  array(array(3, 3, 3),
  124.             'C' =>  array(array(4, 4, 4),
  125.                 'H' =>  array(array(4, 4, 4))),
  126.             'Z' =>  array(array(4, 4, 4),
  127.                 'S' =>  array(array(4, 4, 4))),
  128.             'S' =>  array(array(4, 4, 4),
  129.                 'Z' =>  array(array(4, 4, 4)),
  130.                 'H' =>  array(array(4, 4, 4)),
  131.                 'C' =>  array(
  132.                     'H' =>  array(array(4, 4, 4)))),
  133.             'T' =>  array(
  134.                 'S' =>  array(array(4, 4, 4),
  135.                     'Z' =>  array(array(4, 4, 4)),
  136.                     'C' =>  array(
  137.                         'H' =>  array(array(4, 4, 4)))),
  138.                 'C' =>  array(
  139.                     'H' =>  array(array(4, 4, 4))),
  140.                 'Z' =>  array(array(4, 4, 4))),
  141.             'H' =>  array(array(3, 3, 3)),
  142.             'R' =>  array(
  143.                 'Z' =>  array(array(4, 4, 4)),
  144.                 'S' =>  array(array(4, 4, 4)))),
  145.                
  146.         'U' =>  array(array(0, -1, -1),
  147.             'E' =>  array(array(0, -1, -1)),
  148.             'I' =>  array(array(0, 1, -1)),
  149.             'J' =>  array(array(0, 1, -1)),
  150.             'Y' =>  array(array(0, 1, -1))),
  151.            
  152.         'V' =>  array(array(7, 7, 7)),
  153.        
  154.         'W' =>  array(array(7, 7, 7)),
  155.        
  156.         'X' =>  array(array(5, 54, 54)),
  157.        
  158.         'Y' =>  array(array(1, -1, -1)),
  159.        
  160.         'Z' =>  array(array(4, 4, 4),
  161.             'D' =>  array(array(2, 43, 43),
  162.                 'Z' =>  array(array(2, 4, 4),
  163.                     'H' =>  array(array(2, 4, 4)))),
  164.             'H' =>  array(array(4, 4, 4),
  165.                 'D' => array(array(2, 43, 43),
  166.                     'Z' =>  array(
  167.                         'H' =>  array(array(2, 4, 4))))),
  168.             'S' =>  array(array(4, 4, 4),
  169.                 'H' =>  array(array(4, 4, 4)),
  170.                 'C' =>  array(
  171.                     'H' =>  array(array(4, 4, 4))))));
  172.                    
  173.     $length = strlen($string);
  174.     $output = '';
  175.     $i = 0;
  176.    
  177.     $previous = -1;
  178.    
  179.     while ($i < $length)
  180.     {       
  181.         $current = $last = &$codes[$string[$i]];
  182.        
  183.         for ($j = $k = 1; $k < 7; $k++)
  184.         {           
  185.             if (!isset($string[$i + $k]) ||
  186.                 !isset($current[$string[$i + $k]]))
  187.                 break;
  188.                
  189.             $current = &$current[$string[$i + $k]];                     
  190.            
  191.             if (isset($current[0]))
  192.             {
  193.                 $last = &$current;
  194.                 $j = $k + 1;
  195.             }
  196.         }
  197.        
  198.         fav
  199.            
  200.         if (($code != -1) && ($code != $previous))
  201.             $output .= $code;
  202.            
  203.         $previous = $code;
  204.        
  205.         $i += $j;
  206.            
  207.     }
  208.    
  209.     return str_pad(substr($output, 0, 6), 6, '0');
  210. }
  211.  
  212. //------------------------------------------------------------------------------
  213.  
  214. function dmstring($string)
  215. {
  216.     $is_cyrillic = false;
  217.     if (preg_match('/[А-Яа-я]/iu', $string) === 1)
  218.     {
  219.         $string = translit($string);
  220.         $is_cyrillic = true;
  221.     }
  222.    
  223.     $string = preg_replace(array('/[^\w\s]|\d/iu', '/\b[^\s]{1,3}\b/iu', '/\s{2,}/iu', '/^\s+|\s+$/iu'),
  224.         array('', '', ' '), strtoupper($string));
  225.        
  226.     if (!isset($string[0]))
  227.         return null;
  228.        
  229.     $matches = explode(' ', $string);
  230.     foreach($matches as $key => $match)
  231.         $matches[$key] = dmword($match, $is_cyrillic);         
  232.     return $matches;
  233. }
  234.  
  235. //------------------------------------------------------------------------------
  236.  
  237. function translit($string)
  238. {
  239.     static $ru = array(
  240.         'А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Е', 'е', 'Ё', 'ё', 'Ж', 'ж', 'З', 'з',
  241.         'И', 'и', 'Й', 'й', 'К', 'к', 'Л', 'л', 'М', 'м', 'Н', 'н', 'О', 'о', 'П', 'п', 'Р', 'р',
  242.         'С', 'с', 'Т', 'т', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Ш', 'ш', 'Щ', 'щ',
  243.         'Ъ', 'ъ', 'Ы', 'ы', 'Ь', 'ь', 'Э', 'э', 'Ю', 'ю', 'Я', 'я'
  244.     );
  245.  
  246.     static $en = array(
  247.         'A', 'a', 'B', 'b', 'V', 'v', 'G', 'g', 'D', 'd', 'E', 'e', 'E', 'e', 'Zh', 'zh', 'Z', 'z',
  248.         'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'R', 'r',
  249.         'S', 's', 'T', 't', 'U', 'u', 'F', 'f', 'H', 'h', 'C', 'c', 'Ch', 'ch', 'Sh', 'sh', 'Sch', 'sch',
  250.         '\'', '\'', 'Y', 'y''\'', '\'', 'E', 'e', 'Ju', 'ju', 'Ja', 'ja'
  251.     );
  252.    
  253.     $string = str_replace($ru, $en, $string);   
  254.     return $string;
  255. }
  256.  
  257. //------------------------------------------------------------------------------
  258.  
  259. echo '<pre>'."\n";
  260. echo 'Арнольд Шварцнеггер '.implode(' ', dmstring('Арнольд Шварцнеггер'))."\n";
  261. echo 'Arnold Schwarzenegger '.implode(' ', dmstring('Arnold Schwarzenegger'))."\n";
  262. echo 'Орнольд Шворцнегир '.implode(' ', dmstring('Орнольд Шворцнегир'))."\n";
  263. echo '</pre>';
  264.  
  265. ?>