1 |
<? |
2 |
// ------------------------------------------------------------------------- |
3 |
// $Id$ |
4 |
// ------------------------------------------------------------------------- |
5 |
// $Log$ |
6 |
// ------------------------------------------------------------------------- |
7 |
|
8 |
|
9 |
class TextEncode { |
10 |
|
11 |
var $payload; |
12 |
|
13 |
function TextEncode(&$payload, $args = array()) { |
14 |
$this->payload = &$payload; |
15 |
} |
16 |
|
17 |
function &get() { |
18 |
return $this->payload; |
19 |
} |
20 |
|
21 |
function toUTF8() { |
22 |
$this->_iso_2_utf8($this->payload); |
23 |
} |
24 |
|
25 |
function toISO() { |
26 |
$this->_utf8_2_iso($this->payload); |
27 |
} |
28 |
|
29 |
function _utf8_2_iso(&$payload) { |
30 |
if (is_array($payload)) { |
31 |
foreach ($payload as $key => $val) { |
32 |
if (is_array($payload[$key])) { |
33 |
$this->_utf8_2_iso($payload[$key]); |
34 |
} else { |
35 |
$this->_utf8_2_iso_scalar($payload[$key]); |
36 |
} |
37 |
} |
38 |
} |
39 |
} |
40 |
|
41 |
function _iso_2_utf8(&$payload) { |
42 |
if (is_array($payload)) { |
43 |
foreach ($payload as $key => $val) { |
44 |
if (is_array($payload[$key])) { |
45 |
$this->_iso_2_utf8($payload[$key]); |
46 |
} else { |
47 |
$this->_iso_2_utf8_scalar($payload[$key]); |
48 |
} |
49 |
} |
50 |
} |
51 |
} |
52 |
|
53 |
function _utf8_2_iso_scalar(&$scalar) { |
54 |
$scalar = utf8_decode($scalar); |
55 |
} |
56 |
|
57 |
function _iso_2_utf8_scalar(&$scalar) { |
58 |
$scalar = utf8_encode($scalar); |
59 |
} |
60 |
|
61 |
} |
62 |
|
63 |
?> |