Happy New Year
[squirrelmail.git] / functions / encode / cp1255.php
1 <?php
2
3 /**
4 * cp1255 encoding functions
5 *
6 * takes a string of unicode entities and converts it to a cp1255 encoded string
7 * Unsupported characters are replaced with ?.
8 *
9 * @copyright 2004-2022 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 cp1255
18 * @param string $string text with numeric unicode entities
19 * @return string cp1255 encoded text
20 */
21 function charset_encode_cp1255 ($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_callback("/&#([0-9]+);/",'unicodetocp1255',$string);
26
27 return $string;
28 }
29
30 /**
31 * Return cp1255 symbol when unicode character number is provided
32 *
33 * This function is used internally by charset_encode_cp1255
34 * function. It might be unavailable to other SquirrelMail functions.
35 * Don't use it or make sure, that functions/encode/cp1255.php is
36 * included.
37 *
38 * @param array $matches array with first element a decimal unicode value
39 * @return string cp1255 character
40 */
41 function unicodetocp1255($matches) {
42 $var = $matches[1];
43
44 $cp1255chars=array('160' => "\xA0",
45 '161' => "\xA1",
46 '162' => "\xA2",
47 '163' => "\xA3",
48 '165' => "\xA5",
49 '166' => "\xA6",
50 '167' => "\xA7",
51 '168' => "\xA8",
52 '169' => "\xA9",
53 '171' => "\xAB",
54 '172' => "\xAC",
55 '173' => "\xAD",
56 '174' => "\xAE",
57 '175' => "\xAF",
58 '176' => "\xB0",
59 '177' => "\xB1",
60 '178' => "\xB2",
61 '179' => "\xB3",
62 '180' => "\xB4",
63 '181' => "\xB5",
64 '182' => "\xB6",
65 '183' => "\xB7",
66 '184' => "\xB8",
67 '185' => "\xB9",
68 '187' => "\xBB",
69 '188' => "\xBC",
70 '189' => "\xBD",
71 '190' => "\xBE",
72 '191' => "\xBF",
73 '215' => "\xAA",
74 '247' => "\xBA",
75 '402' => "\x83",
76 '710' => "\x88",
77 '732' => "\x98",
78 '1456' => "\xC0",
79 '1457' => "\xC1",
80 '1458' => "\xC2",
81 '1459' => "\xC3",
82 '1460' => "\xC4",
83 '1461' => "\xC5",
84 '1462' => "\xC6",
85 '1463' => "\xC7",
86 '1464' => "\xC8",
87 '1465' => "\xC9",
88 '1467' => "\xCB",
89 '1468' => "\xCC",
90 '1469' => "\xCD",
91 '1470' => "\xCE",
92 '1471' => "\xCF",
93 '1472' => "\xD0",
94 '1473' => "\xD1",
95 '1474' => "\xD2",
96 '1475' => "\xD3",
97 '1488' => "\xE0",
98 '1489' => "\xE1",
99 '1490' => "\xE2",
100 '1491' => "\xE3",
101 '1492' => "\xE4",
102 '1493' => "\xE5",
103 '1494' => "\xE6",
104 '1495' => "\xE7",
105 '1496' => "\xE8",
106 '1497' => "\xE9",
107 '1498' => "\xEA",
108 '1499' => "\xEB",
109 '1500' => "\xEC",
110 '1501' => "\xED",
111 '1502' => "\xEE",
112 '1503' => "\xEF",
113 '1504' => "\xF0",
114 '1505' => "\xF1",
115 '1506' => "\xF2",
116 '1507' => "\xF3",
117 '1508' => "\xF4",
118 '1509' => "\xF5",
119 '1510' => "\xF6",
120 '1511' => "\xF7",
121 '1512' => "\xF8",
122 '1513' => "\xF9",
123 '1514' => "\xFA",
124 '1520' => "\xD4",
125 '1521' => "\xD5",
126 '1522' => "\xD6",
127 '1523' => "\xD7",
128 '1524' => "\xD8",
129 '8206' => "\xFD",
130 '8207' => "\xFE",
131 '8211' => "\x96",
132 '8212' => "\x97",
133 '8216' => "\x91",
134 '8217' => "\x92",
135 '8218' => "\x82",
136 '8220' => "\x93",
137 '8221' => "\x94",
138 '8222' => "\x84",
139 '8224' => "\x86",
140 '8225' => "\x87",
141 '8226' => "\x95",
142 '8230' => "\x85",
143 '8240' => "\x89",
144 '8249' => "\x8B",
145 '8250' => "\x9B",
146 '8362' => "\xA4",
147 '8364' => "\x80",
148 '8482' => "\x99");
149
150 if (array_key_exists($var,$cp1255chars)) {
151 $ret=$cp1255chars[$var];
152 } else {
153 $ret='?';
154 }
155 return $ret;
156 }