ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExcelUtils.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 /*
25 * Utilities for Microsoft Excel Import/Export
26 *
27 * @author Helmut Schottmüller <hschottm@gmx.de>
28 * @version $Id: class.ilExcelUtils.php 17959 2008-11-18 11:54:58Z hschottm $
29 *
30 */
31 
32 define ("CHARSET_LATIN1", "latin1");
33 define ("CHARSET_MACOS", "macos");
34 
36 {
37  function _convert_text($a_text, $a_target = CHARSET_LATIN1)
38  {
39  $a_text = preg_replace("/<[^>]*?>/", "", $a_text);
40  return utf8_decode($a_text);
41  switch ($a_target)
42  {
43  case CHARSET_LATIN1:
44  $charmap_latin1 = array(
45  utf8_decode("ß") => chr(0xDF),
46  utf8_decode("à") => chr(0xE0),
47  utf8_decode("á") => chr(0xE1),
48  utf8_decode("â") => chr(0xE2),
49  utf8_decode("ã") => chr(0xE3),
50  utf8_decode("ä") => chr(0xE4),
51  utf8_decode("å") => chr(0xE5),
52  utf8_decode("æ") => chr(0xE6),
53  utf8_decode("À") => chr(0xC0),
54  utf8_decode("Á") => chr(0xC1),
55  utf8_decode("Â") => chr(0xC2),
56  utf8_decode("Ã") => chr(0xC3),
57  utf8_decode("Ä") => chr(0xC4),
58  utf8_decode("Å") => chr(0xC5),
59  utf8_decode("Æ") => chr(0xC6),
60  utf8_decode("ç") => chr(0xE7),
61  utf8_decode("Ç") => chr(0xC7),
62  utf8_decode("ð") => chr(0xF0),
63  utf8_decode("è") => chr(0xE8),
64  utf8_decode("é") => chr(0xE9),
65  utf8_decode("ê") => chr(0xEA),
66  utf8_decode("ë") => chr(0xEB),
67  utf8_decode("È") => chr(0xC8),
68  utf8_decode("É") => chr(0xC9),
69  utf8_decode("Ê") => chr(0xCA),
70  utf8_decode("Ë") => chr(0xCB),
71  utf8_decode("ì") => chr(0xEC),
72  utf8_decode("í") => chr(0xED),
73  utf8_decode("î") => chr(0xEE),
74  utf8_decode("ï") => chr(0xEF),
75  utf8_decode("Ì") => chr(0xCC),
76  utf8_decode("Í") => chr(0xCD),
77  utf8_decode("Î") => chr(0xCE),
78  utf8_decode("Ï") => chr(0xCF),
79  utf8_decode("ñ") => chr(0xF1),
80  utf8_decode("Ñ") => chr(0xD1),
81  utf8_decode("ò") => chr(0xF2),
82  utf8_decode("ó") => chr(0xF3),
83  utf8_decode("ô") => chr(0xF4),
84  utf8_decode("õ") => chr(0xF5),
85  utf8_decode("ö") => chr(0xF6),
86  utf8_decode("ø") => chr(0xF8),
87  utf8_decode("Ò") => chr(0xD2),
88  utf8_decode("Ó") => chr(0xD3),
89  utf8_decode("Ô") => chr(0xD4),
90  utf8_decode("Õ") => chr(0xD5),
91  utf8_decode("Ö") => chr(0xD6),
92  utf8_decode("Ø") => chr(0xD8),
93  utf8_decode("ù") => chr(0xF9),
94  utf8_decode("ú") => chr(0xFA),
95  utf8_decode("û") => chr(0xFB),
96  utf8_decode("ü") => chr(0xFC),
97  utf8_decode("Ù") => chr(0xD9),
98  utf8_decode("Ú") => chr(0xDA),
99  utf8_decode("Û") => chr(0xDB),
100  utf8_decode("Ü") => chr(0xDC),
101  utf8_decode("ý") => chr(0xFD),
102  utf8_decode("ÿ") => chr(0xFF),
103  utf8_decode("Ý") => chr(0xDD),
104  utf8_decode("þ") => chr(0xFE),
105  utf8_decode("Þ") => chr(0xDE)
106  );
107  return strtr(str_replace("<br />", " - ", utf8_decode($a_text)), $charmap_latin1);
108  break;
109  case CHARSET_MACOS:
110  $charmap_macos = array(
111  utf8_decode("ß") => chr(0xA7),
112  utf8_decode("à") => chr(0x88),
113  utf8_decode("á") => chr(0x87),
114  utf8_decode("â") => chr(0x89),
115  utf8_decode("ã") => chr(0x8B),
116  utf8_decode("ä") => chr(0x8A),
117  utf8_decode("å") => chr(0x8C),
118  utf8_decode("æ") => chr(0xBE),
119  utf8_decode("À") => chr(0xCB),
120  utf8_decode("Á") => chr(0xE7),
121  utf8_decode("Â") => chr(0xE5),
122  utf8_decode("Ã") => chr(0xCC),
123  utf8_decode("Ä") => chr(0x80),
124  utf8_decode("Å") => chr(0x81),
125  utf8_decode("Æ") => chr(0xAE),
126  utf8_decode("ç") => chr(0x8D),
127  utf8_decode("Ç") => chr(0x82),
128  utf8_decode("ð") => chr(0xB6),
129  utf8_decode("è") => chr(0x8F),
130  utf8_decode("é") => chr(0x8E),
131  utf8_decode("ê") => chr(0x90),
132  utf8_decode("ë") => chr(0x91),
133  utf8_decode("È") => chr(0xE9),
134  utf8_decode("É") => chr(0x83),
135  utf8_decode("Ê") => chr(0xE6),
136  utf8_decode("Ë") => chr(0xE8),
137  utf8_decode("ì") => chr(0x93),
138  utf8_decode("í") => chr(0x92),
139  utf8_decode("î") => chr(0x94),
140  utf8_decode("ï") => chr(0x95),
141  utf8_decode("Ì") => chr(0xED),
142  utf8_decode("Í") => chr(0xEA),
143  utf8_decode("Î") => chr(0xEB),
144  utf8_decode("Ï") => chr(0xEC),
145  utf8_decode("ñ") => chr(0x96),
146  utf8_decode("Ñ") => chr(0x84),
147  utf8_decode("ò") => chr(0x98),
148  utf8_decode("ó") => chr(0x97),
149  utf8_decode("ô") => chr(0x99),
150  utf8_decode("õ") => chr(0x9B),
151  utf8_decode("ö") => chr(0x9A),
152  utf8_decode("ø") => chr(0xBF),
153  utf8_decode("Ò") => chr(0xF1),
154  utf8_decode("Ó") => chr(0xEE),
155  utf8_decode("Ô") => chr(0xEF),
156  utf8_decode("Õ") => chr(0xCD),
157  utf8_decode("Ö") => chr(0x85),
158  utf8_decode("Ø") => chr(0xAF),
159  utf8_decode("ù") => chr(0x9D),
160  utf8_decode("ú") => chr(0x9C),
161  utf8_decode("û") => chr(0x9E),
162  utf8_decode("ü") => chr(0x9F),
163  utf8_decode("Ù") => chr(0xF4),
164  utf8_decode("Ú") => chr(0xF2),
165  utf8_decode("Û") => chr(0xF3),
166  utf8_decode("Ü") => chr(0x86),
167  utf8_decode("ý") => chr(0x79),
168  utf8_decode("ÿ") => chr(0xD8),
169  utf8_decode("Ý") => chr(0x59),
170  utf8_decode("þ") => chr(0x20),
171  utf8_decode("Þ") => chr(0x20)
172  );
173  return strtr(str_replace("<br />", " - ", utf8_decode($a_text)), $charmap_macos);
174  break;
175  case "unknown":
176  default:
177  return $a_text;
178  }
179  }
180 
181 } // END class.ilExcelUtils.php
182 ?>