Fix error caused by typo of variable name
[squirrelmail.git] / functions / encode / koi8_r.php
CommitLineData
9911dc64 1<?php
4b4abf93 2
9911dc64 3/**
4 * koi8-r encoding functions
5 *
6 * takes a string of unicode entities and converts it to a koi8-r encoded string
7 * Unsupported characters are replaced with ?.
8 *
c0d96801 9 * @copyright 2004-2012 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9911dc64 11 * @version $Id$
9911dc64 12 * @package squirrelmail
13 * @subpackage encode
14 */
15
16/**
17 * Converts string to koi8-r
18 * @param string $string text with numeric unicode entities
19 * @return string koi8-r encoded text
20 */
21function charset_encode_koi8_r ($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","unicodetokoi8r('\\1')",$string);
91e0dccc 26
9911dc64 27 return $string;
28}
29
30/**
31 * Return koi8-r symbol when unicode character number is provided
91e0dccc 32 *
33 * This function is used internally by charset_encode_koi8_r
598294a7 34 * function. It might be unavailable to other SquirrelMail functions.
91e0dccc 35 * Don't use it or make sure, that functions/encode/koi8_r.php is
36 * included.
9911dc64 37 *
38 * @param int $var decimal unicode value
39 * @return string koi8-r character
40 */
41function unicodetokoi8r($var) {
42
43 $koi8rchars=array('160' => "\x9A",
44 '169' => "\xBF",
45 '176' => "\x9C",
46 '178' => "\x9D",
47 '183' => "\x9E",
48 '247' => "\x9F",
49 '1025' => "\xB3",
50 '1040' => "\xE1",
51 '1041' => "\xE2",
52 '1042' => "\xF7",
53 '1043' => "\xE7",
54 '1044' => "\xE4",
55 '1045' => "\xE5",
56 '1046' => "\xF6",
57 '1047' => "\xFA",
58 '1048' => "\xE9",
59 '1049' => "\xEA",
60 '1050' => "\xEB",
61 '1051' => "\xEC",
62 '1052' => "\xED",
63 '1053' => "\xEE",
64 '1054' => "\xEF",
65 '1055' => "\xF0",
66 '1056' => "\xF2",
67 '1057' => "\xF3",
68 '1058' => "\xF4",
69 '1059' => "\xF5",
70 '1060' => "\xE6",
71 '1061' => "\xE8",
72 '1062' => "\xE3",
73 '1063' => "\xFE",
74 '1064' => "\xFB",
75 '1065' => "\xFD",
76 '1066' => "\xFF",
77 '1067' => "\xF9",
78 '1068' => "\xF8",
79 '1069' => "\xFC",
80 '1070' => "\xE0",
81 '1071' => "\xF1",
82 '1072' => "\xC1",
83 '1073' => "\xC2",
84 '1074' => "\xD7",
85 '1075' => "\xC7",
86 '1076' => "\xC4",
87 '1077' => "\xC5",
88 '1078' => "\xD6",
89 '1079' => "\xDA",
90 '1080' => "\xC9",
91 '1081' => "\xCA",
92 '1082' => "\xCB",
93 '1083' => "\xCC",
94 '1084' => "\xCD",
95 '1085' => "\xCE",
96 '1086' => "\xCF",
97 '1087' => "\xD0",
98 '1088' => "\xD2",
99 '1089' => "\xD3",
100 '1090' => "\xD4",
101 '1091' => "\xD5",
102 '1092' => "\xC6",
103 '1093' => "\xC8",
104 '1094' => "\xC3",
105 '1095' => "\xDE",
106 '1096' => "\xDB",
107 '1097' => "\xDD",
108 '1098' => "\xDF",
109 '1099' => "\xD9",
110 '1100' => "\xD8",
111 '1101' => "\xDC",
112 '1102' => "\xC0",
113 '1103' => "\xD1",
114 '1105' => "\xA3",
115 '8729' => "\x95",
116 '8730' => "\x96",
117 '8776' => "\x97",
118 '8804' => "\x98",
119 '8805' => "\x99",
120 '8992' => "\x93",
121 '8993' => "\x9B",
122 '9472' => "\x80",
123 '9474' => "\x81",
124 '9484' => "\x82",
125 '9488' => "\x83",
126 '9492' => "\x84",
127 '9496' => "\x85",
128 '9500' => "\x86",
129 '9508' => "\x87",
130 '9516' => "\x88",
131 '9524' => "\x89",
132 '9532' => "\x8A",
133 '9552' => "\xA0",
134 '9553' => "\xA1",
135 '9554' => "\xA2",
136 '9555' => "\xA4",
137 '9556' => "\xA5",
138 '9557' => "\xA6",
139 '9558' => "\xA7",
140 '9559' => "\xA8",
141 '9560' => "\xA9",
142 '9561' => "\xAA",
143 '9562' => "\xAB",
144 '9563' => "\xAC",
145 '9564' => "\xAD",
146 '9565' => "\xAE",
147 '9566' => "\xAF",
148 '9567' => "\xB0",
149 '9568' => "\xB1",
150 '9569' => "\xB2",
151 '9570' => "\xB4",
152 '9571' => "\xB5",
153 '9572' => "\xB6",
154 '9573' => "\xB7",
155 '9574' => "\xB8",
156 '9575' => "\xB9",
157 '9576' => "\xBA",
158 '9577' => "\xBB",
159 '9578' => "\xBC",
160 '9579' => "\xBD",
161 '9580' => "\xBE",
162 '9600' => "\x8B",
163 '9604' => "\x8C",
164 '9608' => "\x8D",
165 '9612' => "\x8E",
166 '9616' => "\x8F",
167 '9617' => "\x90",
168 '9618' => "\x91",
169 '9619' => "\x92",
170 '9632' => "\x94");
171
172 if (array_key_exists($var,$koi8rchars)) {
173 $ret=$koi8rchars[$var];
174 } else {
175 $ret='?';
176 }
177 return $ret;
178}