pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

php private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Master on Thu 9 Jul 13:51 (modification of post by Master view diff)
report abuse | View followups from Master | download | new post

  1. /**
  2.  * Функция для транслитерации русских символов
  3.  *
  4.  * @param string $string
  5.  * @return string
  6.  */
  7. function rus2translit($string) {
  8.     $converter = array(
  9.         'а' => 'a',   'б' => 'b',   'в' => 'v',
  10.         'г' => 'g',   'д' => 'd',   'е' => 'e',
  11.         'ё' => 'e',   'ж' => 'zh',  'з' => 'z',
  12.         'и' => 'i',   'й' => 'y',   'к' => 'k',
  13.         'л' => 'l',   'м' => 'm',   'н' => 'n',
  14.         'о' => 'o',   'п' => 'p',   'р' => 'r',
  15.         'с' => 's',   'т' => 't',   'у' => 'u',
  16.         'ф' => 'f',   'х' => 'h',   'ц' => 'c',
  17.         'ч' => 'ch',  'ш' => 'sh',  'щ' => 'sch',
  18.         'ь' => '\'',  'ы' => 'y',   'ъ' => '\'',
  19.         'э' => 'e',   'ю' => 'yu',  'я' => 'ya',
  20.        
  21.         'А' => 'A',   'Б' => 'B',   'В' => 'V',
  22.         'Г' => 'G',   'Д' => 'D',   'Е' => 'E',
  23.         'Ё' => 'E',   'Ж' => 'Zh',  'З' => 'Z',
  24.         'И' => 'I',   'Й' => 'Y',   'К' => 'K',
  25.         'Л' => 'L',   'М' => 'M',   'Н' => 'N',
  26.         'О' => 'O',   'П' => 'P',   'Р' => 'R',
  27.         'С' => 'S',   'Т' => 'T',   'У' => 'U',
  28.         'Ф' => 'F',   'Х' => 'H',   'Ц' => 'C',
  29.         'Ч' => 'Ch',  'Ш' => 'Sh',  'Щ' => 'Sch',
  30.         'Ь' => '\'',  'Ы' => 'Y',   'Ъ' => '\'',
  31.         'Э' => 'E',   'Ю' => 'Yu',  'Я' => 'Ya',
  32.     );
  33.     return strtr($string, $converter);
  34. }
  35.  
  36. /**
  37.  * Преобразование русских строк в url-подобные, с транслитерацией
  38.  *
  39.  * @param string $str
  40.  * @return string
  41.  */
  42. function str2url($str) {
  43.     // переводим в транслит
  44.     $str = rus2translit($str);
  45.     // в нижний регистр
  46.     $str = strtolower($str);
  47.     // заменям все ненужное нам на "-"
  48.     $str = preg_replace('~[^-a-z0-9_]+~u', '_', $str);
  49.     // удаляем начальные и конечные '-'
  50.     $str = trim($str, "-");
  51.     return $str;
  52. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post