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