Fix error caused by typo of variable name
[squirrelmail.git] / functions / encode / cp1255.php
CommitLineData
9911dc64 1<?php
4b4abf93 2
9911dc64 3/**
4 * cp1255 encoding functions
5 *
6 * takes a string of unicode entities and converts it to a cp1255 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
9911dc64 11 * @version $Id$
9911dc64 12 * @package squirrelmail
13 * @subpackage encode
14 */
15
16/**
17 * Converts string to cp1255
18 * @param string $string text with numeric unicode entities
19 * @return string cp1255 encoded text
20 */
21function charset_encode_cp1255 ($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","unicodetocp1255('\\1')",$string);
91e0dccc 26
9911dc64 27 return $string;
28}
29
30/**
31 * Return cp1255 symbol when unicode character number is provided
91e0dccc 32 *
33 * This function is used internally by charset_encode_cp1255
598294a7 34 * function. It might be unavailable to other SquirrelMail functions.
91e0dccc 35 * Don't use it or make sure, that functions/encode/cp1255.php is
36 * included.
9911dc64 37 *
38 * @param int $var decimal unicode value
39 * @return string cp1255 character
40 */
41function unicodetocp1255($var) {
42
43 $cp1255chars=array('160' => "\xA0",
44 '161' => "\xA1",
45 '162' => "\xA2",
46 '163' => "\xA3",
47 '165' => "\xA5",
48 '166' => "\xA6",
49 '167' => "\xA7",
50 '168' => "\xA8",
51 '169' => "\xA9",
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 '180' => "\xB4",
62 '181' => "\xB5",
63 '182' => "\xB6",
64 '183' => "\xB7",
65 '184' => "\xB8",
66 '185' => "\xB9",
67 '187' => "\xBB",
68 '188' => "\xBC",
69 '189' => "\xBD",
70 '190' => "\xBE",
71 '191' => "\xBF",
72 '215' => "\xAA",
73 '247' => "\xBA",
74 '402' => "\x83",
75 '710' => "\x88",
76 '732' => "\x98",
77 '1456' => "\xC0",
78 '1457' => "\xC1",
79 '1458' => "\xC2",
80 '1459' => "\xC3",
81 '1460' => "\xC4",
82 '1461' => "\xC5",
83 '1462' => "\xC6",
84 '1463' => "\xC7",
85 '1464' => "\xC8",
86 '1465' => "\xC9",
87 '1467' => "\xCB",
88 '1468' => "\xCC",
89 '1469' => "\xCD",
90 '1470' => "\xCE",
91 '1471' => "\xCF",
92 '1472' => "\xD0",
93 '1473' => "\xD1",
94 '1474' => "\xD2",
95 '1475' => "\xD3",
96 '1488' => "\xE0",
97 '1489' => "\xE1",
98 '1490' => "\xE2",
99 '1491' => "\xE3",
100 '1492' => "\xE4",
101 '1493' => "\xE5",
102 '1494' => "\xE6",
103 '1495' => "\xE7",
104 '1496' => "\xE8",
105 '1497' => "\xE9",
106 '1498' => "\xEA",
107 '1499' => "\xEB",
108 '1500' => "\xEC",
109 '1501' => "\xED",
110 '1502' => "\xEE",
111 '1503' => "\xEF",
112 '1504' => "\xF0",
113 '1505' => "\xF1",
114 '1506' => "\xF2",
115 '1507' => "\xF3",
116 '1508' => "\xF4",
117 '1509' => "\xF5",
118 '1510' => "\xF6",
119 '1511' => "\xF7",
120 '1512' => "\xF8",
121 '1513' => "\xF9",
122 '1514' => "\xFA",
123 '1520' => "\xD4",
124 '1521' => "\xD5",
125 '1522' => "\xD6",
126 '1523' => "\xD7",
127 '1524' => "\xD8",
128 '8206' => "\xFD",
129 '8207' => "\xFE",
130 '8211' => "\x96",
131 '8212' => "\x97",
132 '8216' => "\x91",
133 '8217' => "\x92",
134 '8218' => "\x82",
135 '8220' => "\x93",
136 '8221' => "\x94",
137 '8222' => "\x84",
138 '8224' => "\x86",
139 '8225' => "\x87",
140 '8226' => "\x95",
141 '8230' => "\x85",
142 '8240' => "\x89",
143 '8249' => "\x8B",
144 '8250' => "\x9B",
145 '8362' => "\xA4",
146 '8364' => "\x80",
147 '8482' => "\x99");
148
149 if (array_key_exists($var,$cp1255chars)) {
150 $ret=$cp1255chars[$var];
151 } else {
152 $ret='?';
153 }
154 return $ret;
155}