Increment year in copyright notice.
[squirrelmail.git] / functions / encode / iso_8859_7.php
1 <?php
2 /**
3 * iso-8859-7 encoding functions
4 *
5 * takes a string of unicode entities and converts it to a iso-8859-7 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-7
16 * @param string $string text with numeric unicode entities
17 * @return string iso-8859-7 encoded text
18 */
19 function charset_encode_iso_8859_7 ($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","unicodetoiso88597('\\1')",$string);
24 // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88597(hexdec('\\1'))",$string);
25
26 return $string;
27 }
28
29 /**
30 * Return iso-8859-7 symbol when unicode character number is provided
31 *
32 * This function is used internally by charset_encode_iso_8859_7
33 * function. It might be unavailable to other squirrelmail functions.
34 * Don't use it or make sure, that functions/encode/iso_8859_7.php is
35 * included.
36 *
37 * @param int $var decimal unicode value
38 * @return string iso-8859-7 character
39 */
40 function unicodetoiso88597($var) {
41
42 $iso88597chars=array('160' => "\xA0",
43 '163' => "\xA3",
44 '166' => "\xA6",
45 '167' => "\xA7",
46 '168' => "\xA8",
47 '169' => "\xA9",
48 '171' => "\xAB",
49 '172' => "\xAC",
50 '173' => "\xAD",
51 '176' => "\xB0",
52 '177' => "\xB1",
53 '178' => "\xB2",
54 '179' => "\xB3",
55 '183' => "\xB7",
56 '187' => "\xBB",
57 '189' => "\xBD",
58 '900' => "\xB4",
59 '901' => "\xB5",
60 '902' => "\xB6",
61 '904' => "\xB8",
62 '905' => "\xB9",
63 '906' => "\xBA",
64 '908' => "\xBC",
65 '910' => "\xBE",
66 '911' => "\xBF",
67 '912' => "\xC0",
68 '913' => "\xC1",
69 '914' => "\xC2",
70 '915' => "\xC3",
71 '916' => "\xC4",
72 '917' => "\xC5",
73 '918' => "\xC6",
74 '919' => "\xC7",
75 '920' => "\xC8",
76 '921' => "\xC9",
77 '922' => "\xCA",
78 '923' => "\xCB",
79 '924' => "\xCC",
80 '925' => "\xCD",
81 '926' => "\xCE",
82 '927' => "\xCF",
83 '928' => "\xD0",
84 '929' => "\xD1",
85 '931' => "\xD3",
86 '932' => "\xD4",
87 '933' => "\xD5",
88 '934' => "\xD6",
89 '935' => "\xD7",
90 '936' => "\xD8",
91 '937' => "\xD9",
92 '938' => "\xDA",
93 '939' => "\xDB",
94 '940' => "\xDC",
95 '941' => "\xDD",
96 '942' => "\xDE",
97 '943' => "\xDF",
98 '944' => "\xE0",
99 '945' => "\xE1",
100 '946' => "\xE2",
101 '947' => "\xE3",
102 '948' => "\xE4",
103 '949' => "\xE5",
104 '950' => "\xE6",
105 '951' => "\xE7",
106 '952' => "\xE8",
107 '953' => "\xE9",
108 '954' => "\xEA",
109 '955' => "\xEB",
110 '956' => "\xEC",
111 '957' => "\xED",
112 '958' => "\xEE",
113 '959' => "\xEF",
114 '960' => "\xF0",
115 '961' => "\xF1",
116 '962' => "\xF2",
117 '963' => "\xF3",
118 '964' => "\xF4",
119 '965' => "\xF5",
120 '966' => "\xF6",
121 '967' => "\xF7",
122 '968' => "\xF8",
123 '969' => "\xF9",
124 '970' => "\xFA",
125 '971' => "\xFB",
126 '972' => "\xFC",
127 '973' => "\xFD",
128 '974' => "\xFE",
129 '8213' => "\xAF",
130 '8216' => "\xA1",
131 '8217' => "\xA2");
132
133
134 if (array_key_exists($var,$iso88597chars)) {
135 $ret=$iso88597chars[$var];
136 } else {
137 $ret='?';
138 }
139 return $ret;
140 }
141 ?>