Replacing tabs with spaces, trimming white space at EOL and newline at EOF
[squirrelmail.git] / functions / encode / iso_8859_9.php
1 <?php
2 /**
3 * iso-8859-9 encoding functions
4 *
5 * takes a string of unicode entities and converts it to a iso-8859-9 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-9
16 * @param string $string text with numeric unicode entities
17 * @return string iso-8859-9 encoded text
18 */
19 function charset_encode_iso_8859_9 ($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","unicodetoiso88599('\\1')",$string);
24 // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88599(hexdec('\\1'))",$string);
25
26 return $string;
27 }
28
29 /**
30 * Return iso-8859-9 symbol when unicode character number is provided
31 *
32 * This function is used internally by charset_encode_iso_8859_9
33 * function. It might be unavailable to other squirrelmail functions.
34 * Don't use it or make sure, that functions/encode/iso_8859_9.php is
35 * included.
36 *
37 * @param int $var decimal unicode value
38 * @return string iso-8859-9 character
39 */
40 function unicodetoiso88599($var) {
41
42 $iso88599chars=array('160' => "\xA0",
43 '161' => "\xA1",
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 '170' => "\xAA",
53 '171' => "\xAB",
54 '172' => "\xAC",
55 '173' => "\xAD",
56 '174' => "\xAE",
57 '175' => "\xAF",
58 '176' => "\xB0",
59 '177' => "\xB1",
60 '178' => "\xB2",
61 '179' => "\xB3",
62 '180' => "\xB4",
63 '181' => "\xB5",
64 '182' => "\xB6",
65 '183' => "\xB7",
66 '184' => "\xB8",
67 '185' => "\xB9",
68 '186' => "\xBA",
69 '187' => "\xBB",
70 '188' => "\xBC",
71 '189' => "\xBD",
72 '190' => "\xBE",
73 '191' => "\xBF",
74 '192' => "\xC0",
75 '193' => "\xC1",
76 '194' => "\xC2",
77 '195' => "\xC3",
78 '196' => "\xC4",
79 '197' => "\xC5",
80 '198' => "\xC6",
81 '199' => "\xC7",
82 '200' => "\xC8",
83 '201' => "\xC9",
84 '202' => "\xCA",
85 '203' => "\xCB",
86 '204' => "\xCC",
87 '205' => "\xCD",
88 '206' => "\xCE",
89 '207' => "\xCF",
90 '209' => "\xD1",
91 '210' => "\xD2",
92 '211' => "\xD3",
93 '212' => "\xD4",
94 '213' => "\xD5",
95 '214' => "\xD6",
96 '215' => "\xD7",
97 '216' => "\xD8",
98 '217' => "\xD9",
99 '218' => "\xDA",
100 '219' => "\xDB",
101 '220' => "\xDC",
102 '223' => "\xDF",
103 '224' => "\xE0",
104 '225' => "\xE1",
105 '226' => "\xE2",
106 '227' => "\xE3",
107 '228' => "\xE4",
108 '229' => "\xE5",
109 '230' => "\xE6",
110 '231' => "\xE7",
111 '232' => "\xE8",
112 '233' => "\xE9",
113 '234' => "\xEA",
114 '235' => "\xEB",
115 '236' => "\xEC",
116 '237' => "\xED",
117 '238' => "\xEE",
118 '239' => "\xEF",
119 '241' => "\xF1",
120 '242' => "\xF2",
121 '243' => "\xF3",
122 '244' => "\xF4",
123 '245' => "\xF5",
124 '246' => "\xF6",
125 '247' => "\xF7",
126 '248' => "\xF8",
127 '249' => "\xF9",
128 '250' => "\xFA",
129 '251' => "\xFB",
130 '252' => "\xFC",
131 '255' => "\xFF",
132 '286' => "\xD0",
133 '287' => "\xF0",
134 '304' => "\xDD",
135 '305' => "\xFD",
136 '350' => "\xDE",
137 '351' => "\xFE");
138
139
140 if (array_key_exists($var,$iso88599chars)) {
141 $ret=$iso88599chars[$var];
142 } else {
143 $ret='?';
144 }
145 return $ret;
146 }
147 ?>