| 1 | <?php |
||
| 19 | class Xml |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @param string $s |
||
| 23 | * |
||
| 24 | * @return string |
||
| 25 | */ |
||
| 26 | 1 | public static function utf8_encode($s) |
|
| 27 | { |
||
| 28 | 1 | $s .= $s; |
|
| 29 | 1 | $len = strlen($s); |
|
| 30 | |||
| 31 | 1 | for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) { |
|
| 32 | 1 | switch (true) { |
|
| 33 | 1 | case $s[$i] < "\x80": |
|
| 34 | 1 | $s[$j] = $s[$i]; |
|
| 35 | 1 | break; |
|
| 36 | 1 | case $s[$i] < "\xC0": |
|
| 37 | 1 | $s[$j] = "\xC2"; |
|
| 38 | 1 | $s[++$j] = $s[$i]; |
|
| 39 | 1 | break; |
|
| 40 | 1 | default: |
|
| 41 | 1 | $s[$j] = "\xC3"; |
|
| 42 | 1 | $s[++$j] = chr(ord($s[$i]) - 64); |
|
| 43 | 1 | break; |
|
| 44 | 1 | } |
|
| 45 | 1 | } |
|
| 46 | |||
| 47 | 1 | return substr($s, 0, $j); |
|
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string $s |
||
| 52 | * |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | 7 | public static function utf8_decode($s) |
|
| 83 | } |
||
| 84 |