dkanavis

koi8fix

Feb 16th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. // Remove or replace non-koi8 characters from string
  2. function fixkoi8($string, $unknownChar = '?') {
  3.   // Single quotes
  4.   $search[]  = chr(226).chr(128).chr(152);
  5.   $replace[] = "'";
  6.   $search[]  = chr(226).chr(128).chr(153);
  7.   $replace[] = "'";
  8.   // Double quotes, 2 variants
  9.   $search[]  = chr(226).chr(128).chr(156);
  10.   $replace[] = '"';
  11.   $search[]  = chr(226).chr(128).chr(157);
  12.   $replace[] = '"';
  13.   // Long dash
  14.   $search[]  = chr(226).chr(128).chr(147);
  15.   $replace[] = '--';
  16.   // Very long dash
  17.   $search[]  = chr(226).chr(128).chr(148);
  18.   $replace[] = '---';
  19.   // Wildcard
  20.   $search[]  = chr(226).chr(128).chr(162);
  21.   $replace[] = '*';
  22.   // Middle dot
  23.   $search[]  = chr(194).chr(183);
  24.   $replace[] = '*';
  25.   // Three dots
  26.   $search[]  = chr(226).chr(128).chr(166);
  27.   $replace[] = '...';
  28.   // Numero
  29.   $search[] = chr(226).chr(132).chr(150);
  30.   $replace[] = 'No';
  31.   // Apply Replacements
  32.   $string = str_replace($search, $replace, $string);
  33.   // Remove any non-ASCII Characters
  34.   $string = preg_replace('/[^\x01-\x7FА-Яа-яё]/u', $unknownChar, $string);
  35.   return $string;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment