phpDocumentor PHPShopClass
[ class tree: PHPShopClass ] [ all elements ]

Source for file string.class.php

Documentation is available at string.class.php

  1. <?php
  2. /**
  3.  * Áèáëèîòåêà äëÿ ðàáîòû ñî ñòðîêàìè
  4.  * @author PHPShop Software
  5.  * @version 1.0
  6.  * @package PHPShopClass
  7.  */
  8. class PHPShopString {
  9.     
  10.     /**
  11.      * Êîäèðîâêà Win 1251 â UTF8
  12.      * @param string $in_text
  13.      * @return string
  14.      */
  15.     function win_utf8 ($in_text
  16.         $output=""
  17.         $other[1025]="¨"
  18.         $other[1105]="¸"
  19.         $other[1028]="ª"
  20.         $other[1108]="º"
  21.         $other[1030]="I"
  22.         $other[1110]="i"
  23.         $other[1031]="¯"
  24.         $other[1111]="¿"
  25.         
  26.         for ($i=0$i<strlen($in_text)$i++
  27.             if (ord($in_text{$i})>191
  28.                 $output.="&#".(ord($in_text{$i})+848).";"
  29.             else 
  30.                 if (array_search($in_text{$i}$other)===false
  31.                     $output.=$in_text{$i}
  32.                 else 
  33.                     $output.="&#".array_search($in_text{$i}$other).";"
  34.                 
  35.             
  36.         }
  37.         
  38.         return $output
  39.     }
  40.     
  41.     /**
  42.      * Êîäèðîâàíèå utf8 â win1251
  43.      * @param string $s ñòðîêà
  44.      * @return string
  45.      */
  46.     function utf8_win1251($s{
  47.         $sstrtr ($sarray ("\xD0\xB0"=>"à""\xD0\x90"=>"À""\xD0\xB1"=>"á""\xD0\x91"=>"Á""\xD0\xB2"=>"â""\xD0\x92"=>"Â""\xD0\xB3"=>"ã""\xD0\x93"=>"Ã""\xD0\xB4"=>"ä""\xD0\x94"=>"Ä""\xD0\xB5"=>"å""\xD0\x95"=>"Å""\xD1\x91"=>"¸""\xD0\x81"=>"¨""\xD0\xB6"=>"æ""\xD0\x96"=>"Æ""\xD0\xB7"=>"ç""\xD0\x97"=>"Ç""\xD0\xB8"=>"è""\xD0\x98"=>"È""\xD0\xB9"=>"é""\xD0\x99"=>"É""\xD0\xBA"=>"ê""\xD0\x9A"=>"Ê""\xD0\xBB"=>"ë""\xD0\x9B"=>"Ë""\xD0\xBC"=>"ì""\xD0\x9C"=>"Ì""\xD0\xBD"=>"í""\xD0\x9D"=>"Í""\xD0\xBE"=>"î""\xD0\x9E"=>"Î""\xD0\xBF"=>"ï""\xD0\x9F"=>"Ï""\xD1\x80"=>"ð""\xD0\xA0"=>"Ð""\xD1\x81"=>"ñ""\xD0\xA1"=>"Ñ""\xD1\x82"=>"ò""\xD0\xA2"=>"Ò""\xD1\x83"=>"ó""\xD0\xA3"=>"Ó""\xD1\x84"=>"ô""\xD0\xA4"=>"Ô""\xD1\x85"=>"õ""\xD0\xA5"=>"Õ""\xD1\x86"=>"ö""\xD0\xA6"=>"Ö""\xD1\x87"=>"÷""\xD0\xA7"=>"×""\xD1\x88"=>"ø""\xD0\xA8"=>"Ø""\xD1\x89"=>"ù""\xD0\xA9"=>"Ù""\xD1\x8A"=>"ú""\xD0\xAA"=>"Ú""\xD1\x8B"=>"û""\xD0\xAB"=>"Û""\xD1\x8C"=>"ü""\xD0\xAC"=>"Ü""\xD1\x8D"=>"ý""\xD0\xAD"=>"Ý""\xD1\x8E"=>"þ""\xD0\xAE"=>"Þ""\xD1\x8F"=>"ÿ""\xD0\xAF"=>"ß"));
  48.         return $s;
  49.     }
  50.  
  51.  
  52.     /**
  53.      * Ïåðåâîä â ëàòèíèöó
  54.      * @param string $str
  55.      * @return string
  56.      */
  57.     function toLatin($str{
  58.         $str=strtolower($str);
  59.         $str=str_replace("&nbsp;"""$str);
  60.         $str=str_replace("/"""$str);
  61.         $str=str_replace("\\"""$str);
  62.         $str=str_replace("("""$str);
  63.         $str=str_replace(")"""$str);
  64.         $str=str_replace(":"""$str);
  65.         $str=str_replace("-"""$str);
  66.         $str=str_replace(" ""_"$str);
  67.         $str=str_replace("!"""$str);
  68.  
  69.         $new_str='';
  70.  
  71.         $_Array=array(
  72.             "à"=>"a",
  73.             "á"=>"b",
  74.             "â"=>"v",
  75.             "ã"=>"g",
  76.             "ä"=>"d",
  77.             "å"=>"e",
  78.             "¸"=>"e",
  79.             "æ"=>"gh",
  80.             "ç"=>"z",
  81.             "è"=>"i",
  82.             "é"=>"i",
  83.             "ê"=>"k",
  84.             "ë"=>"l",
  85.             "ì"=>"m",
  86.             "í"=>"n",
  87.             "î"=>"o",
  88.             "ï"=>"p",
  89.             "ð"=>"r",
  90.             "ñ"=>"s",
  91.             "ò"=>"t",
  92.             "ó"=>"u",
  93.             "ô"=>"f",
  94.             "õ"=>"h",
  95.             "ö"=>"c",
  96.             "÷"=>"ch",
  97.             "ø"=>"sh",
  98.             "ù"=>"sh",
  99.             "ú"=>"i",
  100.             "û"=>"yi",
  101.             "ü"=>"i",
  102.             "ý"=>"a",
  103.             "þ"=>"u",
  104.             "ÿ"=>"ya",
  105.             "À"=>"a",
  106.             "Á"=>"b",
  107.             "Â"=>"v",
  108.             "Ã"=>"g",
  109.             "Ä"=>"d",
  110.             "¨"=>"e",
  111.             "Æ"=>"gh",
  112.             "Ç"=>"z",
  113.             "È"=>"i",
  114.             "É"=>"i",
  115.             "Ê"=>"k",
  116.             "Ë"=>"l",
  117.             "Ì"=>"m",
  118.             "Í"=>"n",
  119.             "Î"=>"o",
  120.             "Ï"=>"P",
  121.             "Ð"=>"r",
  122.             "Ñ"=>"s",
  123.             "Ò"=>"t",
  124.             "Ó"=>"u",
  125.             "Ô"=>"f",
  126.             "Õ"=>"h",
  127.             "Ö"=>"c",
  128.             "×"=>"ch",
  129.             "Ø"=>"sh",
  130.             "Ù"=>"sh",
  131.             "Ý"=>"a",
  132.             "Þ"=>"u",
  133.             "ß"=>"ya",
  134.             "."=>"_",
  135.             "$"=>"i",
  136.             "%"=>"i",
  137.             "&"=>"and");
  138.  
  139.  
  140.         $chars preg_split('//'$str-1PREG_SPLIT_NO_EMPTY);
  141.  
  142.         foreach($chars as $val)
  143.             if(empty($_Array[$val])) $new_str.=$val;
  144.             else $new_str.=$_Array[$val];
  145.  
  146.         return $new_str;
  147.     }
  148.     
  149. }
  150. ?>

Documentation generated on Mon, 25 Jun 2012 15:09:52 +0400 by phpDocumentor 1.4.3