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