clean up code commented out since 8 y
[squirrelmail.git] / functions / encode / cp1251.php
1 <?php
2
3 /**
4 * cp1251 encoding functions
5 *
6 * takes a string of unicode entities and converts it to a cp1251 encoded string
7 * Unsupported characters are replaced with ?.
8 *
9 * @copyright 2004-2012 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 * @subpackage encode
14 */
15
16 /**
17 * Converts string to cp1251
18 * @param string $string text with numeric unicode entities
19 * @return string cp1251 encoded text
20 */
21 function charset_encode_cp1251 ($string) {
22 // don't run encoding function, if there is no encoded characters
23 if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
24
25 $string=preg_replace("/&#([0-9]+);/e","unicodetocp1251('\\1')",$string);
26
27 return $string;
28 }
29
30 /**
31 * Return cp1251 symbol when unicode character number is provided
32 *
33 * This function is used internally by charset_encode_cp1251
34 * function. It might be unavailable to other SquirrelMail functions.
35 * Don't use it or make sure, that functions/encode/cp1251.php is
36 * included.
37 *
38 * @param int $var decimal unicode value
39 * @return string cp1251 character
40 */
41 function unicodetocp1251($var) {
42
43 $cp1251chars=array('160' => "\xA0",
44 '164' => "\xA4",
45 '166' => "\xA6",
46 '167' => "\xA7",
47 '169' => "\xA9",
48 '171' => "\xAB",
49 '172' => "\xAC",
50 '173' => "\xAD",
51 '174' => "\xAE",
52 '176' => "\xB0",
53 '177' => "\xB1",
54 '181' => "\xB5",
55 '182' => "\xB6",
56 '183' => "\xB7",
57 '187' => "\xBB",
58 '1025' => "\xA8",
59 '1026' => "\x80",
60 '1027' => "\x81",
61 '1028' => "\xAA",
62 '1029' => "\xBD",
63 '1030' => "\xB2",
64 '1031' => "\xAF",
65 '1032' => "\xA3",
66 '1033' => "\x8A",
67 '1034' => "\x8C",
68 '1035' => "\x8E",
69 '1036' => "\x8D",
70 '1038' => "\xA1",
71 '1039' => "\x8F",
72 '1040' => "\xC0",
73 '1041' => "\xC1",
74 '1042' => "\xC2",
75 '1043' => "\xC3",
76 '1044' => "\xC4",
77 '1045' => "\xC5",
78 '1046' => "\xC6",
79 '1047' => "\xC7",
80 '1048' => "\xC8",
81 '1049' => "\xC9",
82 '1050' => "\xCA",
83 '1051' => "\xCB",
84 '1052' => "\xCC",
85 '1053' => "\xCD",
86 '1054' => "\xCE",
87 '1055' => "\xCF",
88 '1056' => "\xD0",
89 '1057' => "\xD1",
90 '1058' => "\xD2",
91 '1059' => "\xD3",
92 '1060' => "\xD4",
93 '1061' => "\xD5",
94 '1062' => "\xD6",
95 '1063' => "\xD7",
96 '1064' => "\xD8",
97 '1065' => "\xD9",
98 '1066' => "\xDA",
99 '1067' => "\xDB",
100 '1068' => "\xDC",
101 '1069' => "\xDD",
102 '1070' => "\xDE",
103 '1071' => "\xDF",
104 '1072' => "\xE0",
105 '1073' => "\xE1",
106 '1074' => "\xE2",
107 '1075' => "\xE3",
108 '1076' => "\xE4",
109 '1077' => "\xE5",
110 '1078' => "\xE6",
111 '1079' => "\xE7",
112 '1080' => "\xE8",
113 '1081' => "\xE9",
114 '1082' => "\xEA",
115 '1083' => "\xEB",
116 '1084' => "\xEC",
117 '1085' => "\xED",
118 '1086' => "\xEE",
119 '1087' => "\xEF",
120 '1088' => "\xF0",
121 '1089' => "\xF1",
122 '1090' => "\xF2",
123 '1091' => "\xF3",
124 '1092' => "\xF4",
125 '1093' => "\xF5",
126 '1094' => "\xF6",
127 '1095' => "\xF7",
128 '1096' => "\xF8",
129 '1097' => "\xF9",
130 '1098' => "\xFA",
131 '1099' => "\xFB",
132 '1100' => "\xFC",
133 '1101' => "\xFD",
134 '1102' => "\xFE",
135 '1103' => "\xFF",
136 '1105' => "\xB8",
137 '1106' => "\x90",
138 '1107' => "\x83",
139 '1108' => "\xBA",
140 '1109' => "\xBE",
141 '1110' => "\xB3",
142 '1111' => "\xBF",
143 '1112' => "\xBC",
144 '1113' => "\x9A",
145 '1114' => "\x9C",
146 '1115' => "\x9E",
147 '1116' => "\x9D",
148 '1118' => "\xA2",
149 '1119' => "\x9F",
150 '1168' => "\xA5",
151 '1169' => "\xB4",
152 '8211' => "\x96",
153 '8212' => "\x97",
154 '8216' => "\x91",
155 '8217' => "\x92",
156 '8218' => "\x82",
157 '8220' => "\x93",
158 '8221' => "\x94",
159 '8222' => "\x84",
160 '8224' => "\x86",
161 '8225' => "\x87",
162 '8226' => "\x95",
163 '8230' => "\x85",
164 '8240' => "\x89",
165 '8249' => "\x8B",
166 '8250' => "\x9B",
167 '8364' => "\x88",
168 '8470' => "\xB9",
169 '8482' => "\x99");
170
171 if (array_key_exists($var,$cp1251chars)) {
172 $ret=$cp1251chars[$var];
173 } else {
174 $ret='?';
175 }
176 return $ret;
177 }