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