Advertisement
zero50x

URL-кодирование прямое и обратное

Jun 1st, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.36 KB | None | 0 0
  1. function str_to_code($text){
  2.     $text = str_replace('а', '%D0%B0', $text);
  3.     $text = str_replace('б', '%D0%B1', $text);
  4.     $text = str_replace('в', '%D0%B2', $text);
  5.     $text = str_replace('г', '%D0%B3', $text);
  6.     $text = str_replace('д', '%D0%B4', $text);
  7.     $text = str_replace('е', '%D0%B5', $text);
  8.     $text = str_replace('ё', '%D1%91', $text);
  9.     $text = str_replace('ж', '%D0%B6', $text);
  10.     $text = str_replace('з', '%D0%B7', $text);
  11.     $text = str_replace('и', '%D0%B8', $text);
  12.     $text = str_replace('й', '%D0%B9', $text);
  13.     $text = str_replace('к', '%D0%BA', $text);
  14.     $text = str_replace('л', '%D0%BB', $text);
  15.     $text = str_replace('м', '%D0%BC', $text);
  16.     $text = str_replace('н', '%D0%BD', $text);
  17.     $text = str_replace('о', '%D0%BE', $text);
  18.     $text = str_replace('п', '%D0%BF', $text);
  19.     $text = str_replace('р', '%D1%80', $text);
  20.     $text = str_replace('с', '%D1%81', $text);
  21.     $text = str_replace('т', '%D1%82', $text);
  22.     $text = str_replace('у', '%D1%83', $text);
  23.     $text = str_replace('ф', '%D1%84', $text);
  24.     $text = str_replace('х', '%D1%85', $text);
  25.     $text = str_replace('ц', '%D1%86', $text);
  26.     $text = str_replace('ч', '%D1%87', $text);
  27.     $text = str_replace('ш', '%D1%88', $text);
  28.     $text = str_replace('щ', '%D1%89', $text);
  29.     $text = str_replace('ъ', '%D1%8A', $text);
  30.     $text = str_replace('ы', '%D1%8B', $text);
  31.     $text = str_replace('ь', '%D1%8C', $text);
  32.     $text = str_replace('э', '%D1%8D', $text);
  33.     $text = str_replace('ю', '%D1%8E', $text);
  34.     $text = str_replace('я', '%D1%8F', $text);
  35.  
  36.     $text = str_replace('А', '%D0%90', $text);
  37.     $text = str_replace('Б', '%D0%91', $text);
  38.     $text = str_replace('В', '%D0%92', $text);
  39.     $text = str_replace('Г', '%D0%93', $text);
  40.     $text = str_replace('Д', '%D0%94', $text);
  41.     $text = str_replace('Е', '%D0%95', $text);
  42.     $text = str_replace('Ё', '%D0%81', $text);
  43.     $text = str_replace('Ж', '%D0%96', $text);
  44.     $text = str_replace('З', '%D0%97', $text);
  45.     $text = str_replace('И', '%D0%98', $text);
  46.     $text = str_replace('Й', '%D0%99', $text);
  47.     $text = str_replace('К', '%D0%9A', $text);
  48.     $text = str_replace('Л', '%D0%9B', $text);
  49.     $text = str_replace('М', '%D0%9C', $text);
  50.     $text = str_replace('Н', '%D0%9D', $text);
  51.     $text = str_replace('О', '%D0%9E', $text);
  52.     $text = str_replace('П', '%D0%9F', $text);
  53.     $text = str_replace('Р', '%D0%A0', $text);
  54.     $text = str_replace('С', '%D0%A1', $text);
  55.     $text = str_replace('Т', '%D0%A2', $text);
  56.     $text = str_replace('У', '%D0%A3', $text);
  57.     $text = str_replace('Ф', '%D0%A4', $text);
  58.     $text = str_replace('Х', '%D0%A5', $text);
  59.     $text = str_replace('Ц', '%D0%A6', $text);
  60.     $text = str_replace('Ч', '%D0%A7', $text);
  61.     $text = str_replace('Ш', '%D0%A8', $text);
  62.     $text = str_replace('Щ', '%D0%A9', $text);
  63.     $text = str_replace('Ъ', '%D0%AA', $text);
  64.     $text = str_replace('Ы', '%D0%AB', $text);
  65.     $text = str_replace('Ь', '%D0%AC', $text);
  66.     $text = str_replace('Э', '%D0%AD', $text);
  67.     $text = str_replace('Ю', '%D0%AE', $text);
  68.     $text = str_replace('Я', '%D0%AF', $text);
  69.  
  70.     $text = str_replace(' ', '%20', $text);
  71.     $text = str_replace('+', '%2B', $text);
  72.     $text = str_replace('(', '%28', $text);
  73.     $text = str_replace(')', '%29', $text);
  74.  
  75.     return $text;
  76. }
  77.  
  78.  
  79. function code_to_str($text){
  80.     $text = str_replace('%D0%B0', 'а', $text);
  81.     $text = str_replace('%D0%B1', 'б', $text);
  82.     $text = str_replace('%D0%B2', 'в', $text);
  83.     $text = str_replace('%D0%B3', 'г', $text);
  84.     $text = str_replace('%D0%B4', 'д', $text);
  85.     $text = str_replace('%D0%B5', 'е', $text);
  86.     $text = str_replace('%D1%91', 'ё', $text);
  87.     $text = str_replace('%D0%B6', 'ж', $text);
  88.     $text = str_replace('%D0%B7', 'з', $text);
  89.     $text = str_replace('%D0%B8', 'и', $text);
  90.     $text = str_replace('%D0%B9', 'й', $text);
  91.     $text = str_replace('%D0%BA', 'к', $text);
  92.     $text = str_replace('%D0%BB', 'л', $text);
  93.     $text = str_replace('%D0%BC', 'м', $text);
  94.     $text = str_replace('%D0%BD', 'н', $text);
  95.     $text = str_replace('%D0%BE', 'о', $text);
  96.     $text = str_replace('%D0%BF', 'п', $text);
  97.     $text = str_replace('%D1%80', 'р', $text);
  98.     $text = str_replace('%D1%81', 'с', $text);
  99.     $text = str_replace('%D1%82', 'т', $text);
  100.     $text = str_replace('%D1%83', 'у', $text);
  101.     $text = str_replace('%D1%84', 'ф', $text);
  102.     $text = str_replace('%D1%85', 'х', $text);
  103.     $text = str_replace('%D1%86', 'ц', $text);
  104.     $text = str_replace('%D1%87', 'ч', $text);
  105.     $text = str_replace('%D1%88', 'ш', $text);
  106.     $text = str_replace('%D1%89', 'щ', $text);
  107.     $text = str_replace('%D1%8A', 'ъ', $text);
  108.     $text = str_replace('%D1%8B', 'ы', $text);
  109.     $text = str_replace('%D1%8C', 'ь', $text);
  110.     $text = str_replace('%D1%8D', 'э', $text);
  111.     $text = str_replace('%D1%8E', 'ю', $text);
  112.     $text = str_replace('%D1%8F', 'я', $text);
  113.     $text = str_replace('%D0%90', 'А', $text);
  114.     $text = str_replace('%D0%91', 'Б', $text);
  115.     $text = str_replace('%D0%92', 'В', $text);
  116.     $text = str_replace('%D0%93', 'Г', $text);
  117.     $text = str_replace('%D0%94', 'Д', $text);
  118.     $text = str_replace('%D0%95', 'Е', $text);
  119.     $text = str_replace('%D0%81', 'Ё', $text);
  120.     $text = str_replace('%D0%96', 'Ж', $text);
  121.     $text = str_replace('%D0%97', 'З', $text);
  122.     $text = str_replace('%D0%98', 'И', $text);
  123.     $text = str_replace('%D0%99', 'Й', $text);
  124.     $text = str_replace('%D0%9A', 'К', $text);
  125.     $text = str_replace('%D0%9B', 'Л', $text);
  126.     $text = str_replace('%D0%9C', 'М', $text);
  127.     $text = str_replace('%D0%9D', 'Н', $text);
  128.     $text = str_replace('%D0%9E', 'О', $text);
  129.     $text = str_replace('%D0%9F', 'П', $text);
  130.     $text = str_replace('%D0%A0', 'Р', $text);
  131.     $text = str_replace('%D0%A1', 'С', $text);
  132.     $text = str_replace('%D0%A2', 'Т', $text);
  133.     $text = str_replace('%D0%A3', 'У', $text);
  134.     $text = str_replace('%D0%A4', 'Ф', $text);
  135.     $text = str_replace('%D0%A5', 'Х', $text);
  136.     $text = str_replace('%D0%A6', 'Ц', $text);
  137.     $text = str_replace('%D0%A7', 'Ч', $text);
  138.     $text = str_replace('%D0%A8', 'Ш', $text);
  139.     $text = str_replace('%D0%A9', 'Щ', $text);
  140.     $text = str_replace('%D0%AA', 'Ъ', $text);
  141.     $text = str_replace('%D0%AB', 'Ы', $text);
  142.     $text = str_replace('%D0%AC', 'Ь', $text);
  143.     $text = str_replace('%D0%AD', 'Э', $text);
  144.     $text = str_replace('%D0%AE', 'Ю', $text);
  145.     $text = str_replace('%D0%AF', 'Я', $text);
  146.     $text = str_replace('%20', ' ', $text);
  147.     $text = str_replace('%2B', '+', $text);
  148.     $text = str_replace('%28', '(', $text);
  149.     $text = str_replace('%29', ')', $text);
  150.  
  151.     return $text;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement