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