feee76c9 |
1 | <?php |
4b4abf93 |
2 | |
feee76c9 |
3 | /** |
4 | * iso-8859-15 encoding functions |
5 | * |
6 | * takes a string of unicode entities and converts it to a iso-8859-15 encoded string |
7 | * Unsupported characters are replaced with ?. |
8 | * |
47ccfad4 |
9 | * @copyright © 2004-2006 The SquirrelMail Project Team |
4b4abf93 |
10 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
feee76c9 |
11 | * @version $Id$ |
feee76c9 |
12 | * @package squirrelmail |
13 | * @subpackage encode |
14 | */ |
15 | |
16 | /** |
17 | * Converts string to iso-8859-15 |
18 | * @param string $string text with numeric unicode entities |
19 | * @return string iso-8859-15 encoded text |
20 | */ |
21 | function charset_encode_iso_8859_15 ($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","unicodetoiso885915('\\1')",$string); |
26 | // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso885915(hexdec('\\1'))",$string); |
91e0dccc |
27 | |
feee76c9 |
28 | return $string; |
29 | } |
30 | |
31 | /** |
32 | * Return iso-8859-15 symbol when unicode character number is provided |
91e0dccc |
33 | * |
34 | * This function is used internally by charset_encode_iso_8859_15 |
598294a7 |
35 | * function. It might be unavailable to other SquirrelMail functions. |
91e0dccc |
36 | * Don't use it or make sure, that functions/encode/iso_8859_15.php is |
37 | * included. |
feee76c9 |
38 | * |
39 | * @param int $var decimal unicode value |
40 | * @return string iso-8859-15 character |
41 | */ |
42 | function unicodetoiso885915($var) { |
43 | |
44 | $iso885915chars=array('160' => "\xA0", |
45 | '161' => "\xA1", |
46 | '162' => "\xA2", |
47 | '163' => "\xA3", |
48 | '165' => "\xA5", |
49 | '167' => "\xA7", |
50 | '169' => "\xA9", |
51 | '170' => "\xAA", |
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 | '181' => "\xB5", |
62 | '182' => "\xB6", |
63 | '183' => "\xB7", |
64 | '185' => "\xB9", |
65 | '186' => "\xBA", |
66 | '187' => "\xBB", |
67 | '191' => "\xBF", |
68 | '192' => "\xC0", |
69 | '193' => "\xC1", |
70 | '194' => "\xC2", |
71 | '195' => "\xC3", |
72 | '196' => "\xC4", |
73 | '197' => "\xC5", |
74 | '198' => "\xC6", |
75 | '199' => "\xC7", |
76 | '200' => "\xC8", |
77 | '201' => "\xC9", |
78 | '202' => "\xCA", |
79 | '203' => "\xCB", |
80 | '204' => "\xCC", |
81 | '205' => "\xCD", |
82 | '206' => "\xCE", |
83 | '207' => "\xCF", |
84 | '208' => "\xD0", |
85 | '209' => "\xD1", |
86 | '210' => "\xD2", |
87 | '211' => "\xD3", |
88 | '212' => "\xD4", |
89 | '213' => "\xD5", |
90 | '214' => "\xD6", |
91 | '215' => "\xD7", |
92 | '216' => "\xD8", |
93 | '217' => "\xD9", |
94 | '218' => "\xDA", |
95 | '219' => "\xDB", |
96 | '220' => "\xDC", |
97 | '221' => "\xDD", |
98 | '222' => "\xDE", |
99 | '223' => "\xDF", |
100 | '224' => "\xE0", |
101 | '225' => "\xE1", |
102 | '226' => "\xE2", |
103 | '227' => "\xE3", |
104 | '228' => "\xE4", |
105 | '229' => "\xE5", |
106 | '230' => "\xE6", |
107 | '231' => "\xE7", |
108 | '232' => "\xE8", |
109 | '233' => "\xE9", |
110 | '234' => "\xEA", |
111 | '235' => "\xEB", |
112 | '236' => "\xEC", |
113 | '237' => "\xED", |
114 | '238' => "\xEE", |
115 | '239' => "\xEF", |
116 | '240' => "\xF0", |
117 | '241' => "\xF1", |
118 | '242' => "\xF2", |
119 | '243' => "\xF3", |
120 | '244' => "\xF4", |
121 | '245' => "\xF5", |
122 | '246' => "\xF6", |
123 | '247' => "\xF7", |
124 | '248' => "\xF8", |
125 | '249' => "\xF9", |
126 | '250' => "\xFA", |
127 | '251' => "\xFB", |
128 | '252' => "\xFC", |
129 | '253' => "\xFD", |
130 | '254' => "\xFE", |
131 | '255' => "\xFF", |
132 | '338' => "\xBC", |
133 | '339' => "\xBD", |
134 | '352' => "\xA6", |
135 | '353' => "\xA8", |
136 | '376' => "\xBE", |
137 | '381' => "\xB4", |
138 | '382' => "\xB8", |
139 | '8364' => "\xA4"); |
140 | |
141 | if (array_key_exists($var,$iso885915chars)) { |
142 | $ret=$iso885915chars[$var]; |
143 | } else { |
144 | $ret='?'; |
145 | } |
146 | return $ret; |
147 | } |