<?php
//# перекодирование строки CP1251 в UNICODE
//# для экономии размера заменяем одинаковые по начертанию
//# символы кириллицы на символы латиницы
//# (чтобы сэкономить - вместо "&x0430" ("а" рус.) рисуем "a" ("a" eng.))

function unicod ($in_text) {
  
$rus "АВЕЗКМНОРСТХаеорсух";
  
$eng "ABE3KMHOPCTXaeopcyx";

  
$output="";
  
$other[1025]="Ё";
  
$other[1105]="ё";
  
$other[1028]="Є";
  
$other[1108]="є";
  
$other[1030]="I";
  
$other[1110]="i";
  
$other[1031]="Ї";
  
$other[1111]="ї";
  
$l strlen($rus);
  for (
$i=0$i<strlen($in_text); $i++){
    
$rep=0;
    
$c substr($in_text,$i,1);
    for(
$j=0;$j<$l;$j++) {
      if(
$c == substr($rus,$j,1)) {
        
$output .= substr($eng,$j,1);
        
$rep=1;
        break;
      }
    }
    if(!
$rep) {
      if (
ord($c)>191){
        
$output.="&#".(ord($c)+848).";";
      } else {
        if (
array_search($c$other)===false){
          
$output.=$c;
        } else {
          
$output.="&#".array_search($c$other).";";
        }
      }
    }
  }
  return 
$output;
}
?>