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