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