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