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