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