clean up code commented out since 8 y
[squirrelmail.git] / functions / encode / cp1256.php
1 <?php
2
3 /**
4 * cp1256 encoding functions
5 *
6 * takes a string of unicode entities and converts it to a cp1256 encoded string
7 * Unsupported characters are replaced with ?.
8 *
9 * @copyright 2004-2012 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 cp1256
18 * @param string $string text with numeric unicode entities
19 * @return string cp1256 encoded text
20 */
21 function charset_encode_cp1256 ($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","unicodetocp1256('\\1')",$string);
26
27 return $string;
28 }
29
30 /**
31 * Return cp1256 symbol when unicode character number is provided
32 *
33 * This function is used internally by charset_encode_cp1256
34 * function. It might be unavailable to other SquirrelMail functions.
35 * Don't use it or make sure, that functions/encode/cp1256.php is
36 * included.
37 *
38 * @param int $var decimal unicode value
39 * @return string cp1256 character
40 */
41 function unicodetocp1256($var) {
42
43 $cp1256chars=array('160' => "\xA0",
44 '162' => "\xA2",
45 '163' => "\xA3",
46 '164' => "\xA4",
47 '165' => "\xA5",
48 '166' => "\xA6",
49 '167' => "\xA7",
50 '168' => "\xA8",
51 '169' => "\xA9",
52 '171' => "\xAB",
53 '172' => "\xAC",
54 '173' => "\xAD",
55 '174' => "\xAE",
56 '175' => "\xAF",
57 '176' => "\xB0",
58 '177' => "\xB1",
59 '178' => "\xB2",
60 '179' => "\xB3",
61 '180' => "\xB4",
62 '181' => "\xB5",
63 '182' => "\xB6",
64 '183' => "\xB7",
65 '184' => "\xB8",
66 '185' => "\xB9",
67 '187' => "\xBB",
68 '188' => "\xBC",
69 '189' => "\xBD",
70 '190' => "\xBE",
71 '215' => "\xD7",
72 '224' => "\xE0",
73 '226' => "\xE2",
74 '231' => "\xE7",
75 '232' => "\xE8",
76 '233' => "\xE9",
77 '234' => "\xEA",
78 '235' => "\xEB",
79 '238' => "\xEE",
80 '239' => "\xEF",
81 '244' => "\xF4",
82 '247' => "\xF7",
83 '249' => "\xF9",
84 '251' => "\xFB",
85 '252' => "\xFC",
86 '338' => "\x8C",
87 '339' => "\x9C",
88 '402' => "\x83",
89 '710' => "\x88",
90 '1548' => "\xA1",
91 '1563' => "\xBA",
92 '1567' => "\xBF",
93 '1569' => "\xC1",
94 '1570' => "\xC2",
95 '1571' => "\xC3",
96 '1572' => "\xC4",
97 '1573' => "\xC5",
98 '1574' => "\xC6",
99 '1575' => "\xC7",
100 '1576' => "\xC8",
101 '1577' => "\xC9",
102 '1578' => "\xCA",
103 '1579' => "\xCB",
104 '1580' => "\xCC",
105 '1581' => "\xCD",
106 '1582' => "\xCE",
107 '1583' => "\xCF",
108 '1584' => "\xD0",
109 '1585' => "\xD1",
110 '1586' => "\xD2",
111 '1587' => "\xD3",
112 '1588' => "\xD4",
113 '1589' => "\xD5",
114 '1590' => "\xD6",
115 '1591' => "\xD8",
116 '1592' => "\xD9",
117 '1593' => "\xDA",
118 '1594' => "\xDB",
119 '1600' => "\xDC",
120 '1601' => "\xDD",
121 '1602' => "\xDE",
122 '1603' => "\xDF",
123 '1604' => "\xE1",
124 '1605' => "\xE3",
125 '1606' => "\xE4",
126 '1607' => "\xE5",
127 '1608' => "\xE6",
128 '1609' => "\xEC",
129 '1610' => "\xED",
130 '1611' => "\xF0",
131 '1612' => "\xF1",
132 '1613' => "\xF2",
133 '1614' => "\xF3",
134 '1615' => "\xF5",
135 '1616' => "\xF6",
136 '1617' => "\xF8",
137 '1618' => "\xFA",
138 '1657' => "\x8A",
139 '1662' => "\x81",
140 '1670' => "\x8D",
141 '1672' => "\x8F",
142 '1681' => "\x9A",
143 '1688' => "\x8E",
144 '1705' => "\x98",
145 '1711' => "\x90",
146 '1722' => "\x9F",
147 '1726' => "\xAA",
148 '1729' => "\xC0",
149 '1746' => "\xFF",
150 '8204' => "\x9D",
151 '8205' => "\x9E",
152 '8206' => "\xFD",
153 '8207' => "\xFE",
154 '8211' => "\x96",
155 '8212' => "\x97",
156 '8216' => "\x91",
157 '8217' => "\x92",
158 '8218' => "\x82",
159 '8220' => "\x93",
160 '8221' => "\x94",
161 '8222' => "\x84",
162 '8224' => "\x86",
163 '8225' => "\x87",
164 '8226' => "\x95",
165 '8230' => "\x85",
166 '8240' => "\x89",
167 '8249' => "\x8B",
168 '8250' => "\x9B",
169 '8364' => "\x80",
170 '8482' => "\x99");
171
172 if (array_key_exists($var,$cp1256chars)) {
173 $ret=$cp1256chars[$var];
174 } else {
175 $ret='?';
176 }
177 return $ret;
178 }