adding iso8859-15 support
[squirrelmail.git] / functions / encode / iso_8859_2.php
1 <?php
2 /**
3 * iso-8859-2 encoding functions
4 *
5 * takes a string of unicode entities and converts it to a iso-8859-2 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 iso-8859-2
16 * @param string $string text with numeric unicode entities
17 * @return string iso-8859-2 encoded text
18 */
19 function charset_encode_iso_8859_2 ($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","unicodetoiso88592('\\1')",$string);
24 // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88592(hexdec('\\1'))",$string);
25
26 return $string;
27 }
28
29 /**
30 * Return iso-8859-2 symbol when unicode character number is provided
31 *
32 * This function is used internally by charset_encode_iso_8859_2
33 * function. It might be unavailable to other squirrelmail functions.
34 * Don't use it or make sure, that functions/encode/iso_8859_2.php is
35 * included.
36 *
37 * @param int $var decimal unicode value
38 * @return string iso-8859-2 character
39 */
40 function unicodetoiso88592($var) {
41
42 $iso88592chars=array('160' => "\xA0",
43 '164' => "\xA4",
44 '167' => "\xA7",
45 '168' => "\xA8",
46 '173' => "\xAD",
47 '176' => "\xB0",
48 '180' => "\xB4",
49 '184' => "\xB8",
50 '193' => "\xC1",
51 '194' => "\xC2",
52 '196' => "\xC4",
53 '199' => "\xC7",
54 '201' => "\xC9",
55 '203' => "\xCB",
56 '205' => "\xCD",
57 '206' => "\xCE",
58 '211' => "\xD3",
59 '212' => "\xD4",
60 '214' => "\xD6",
61 '215' => "\xD7",
62 '218' => "\xDA",
63 '220' => "\xDC",
64 '221' => "\xDD",
65 '223' => "\xDF",
66 '225' => "\xE1",
67 '226' => "\xE2",
68 '228' => "\xE4",
69 '231' => "\xE7",
70 '233' => "\xE9",
71 '235' => "\xEB",
72 '237' => "\xED",
73 '238' => "\xEE",
74 '243' => "\xF3",
75 '244' => "\xF4",
76 '246' => "\xF6",
77 '247' => "\xF7",
78 '250' => "\xFA",
79 '252' => "\xFC",
80 '253' => "\xFD",
81 '258' => "\xC3",
82 '259' => "\xE3",
83 '260' => "\xA1",
84 '261' => "\xB1",
85 '262' => "\xC6",
86 '263' => "\xE6",
87 '268' => "\xC8",
88 '269' => "\xE8",
89 '270' => "\xCF",
90 '271' => "\xEF",
91 '272' => "\xD0",
92 '273' => "\xF0",
93 '280' => "\xCA",
94 '281' => "\xEA",
95 '282' => "\xCC",
96 '283' => "\xEC",
97 '313' => "\xC5",
98 '314' => "\xE5",
99 '317' => "\xA5",
100 '318' => "\xB5",
101 '321' => "\xA3",
102 '322' => "\xB3",
103 '323' => "\xD1",
104 '324' => "\xF1",
105 '327' => "\xD2",
106 '328' => "\xF2",
107 '336' => "\xD5",
108 '337' => "\xF5",
109 '340' => "\xC0",
110 '341' => "\xE0",
111 '344' => "\xD8",
112 '345' => "\xF8",
113 '346' => "\xA6",
114 '347' => "\xB6",
115 '350' => "\xAA",
116 '351' => "\xBA",
117 '352' => "\xA9",
118 '353' => "\xB9",
119 '354' => "\xDE",
120 '355' => "\xFE",
121 '356' => "\xAB",
122 '357' => "\xBB",
123 '366' => "\xD9",
124 '367' => "\xF9",
125 '368' => "\xDB",
126 '369' => "\xFB",
127 '377' => "\xAC",
128 '378' => "\xBC",
129 '379' => "\xAF",
130 '380' => "\xBF",
131 '381' => "\xAE",
132 '382' => "\xBE",
133 '711' => "\xB7",
134 '728' => "\xA2",
135 '729' => "\xFF",
136 '731' => "\xB2",
137 '733' => "\xBD");
138
139
140 if (array_key_exists($var,$iso88592chars)) {
141 $ret=$iso88592chars[$var];
142 } else {
143 $ret='?';
144 }
145 return $ret;
146 }
147 ?>