| @@ 34-41 (lines=8) @@ | ||
| 31 | * @param string $from source encoding |
|
| 32 | * @return string UTF-8 encoded string, original string if iconv failed. |
|
| 33 | */ |
|
| 34 | public static function toUTF8($string, $from) |
|
| 35 | { |
|
| 36 | if ($from != 'UTF-8') { |
|
| 37 | $s = iconv($from, 'UTF-8', $string); //to UTF-8 |
|
| 38 | return $s !== false ? $s : $string; //it could return false |
|
| 39 | } |
|
| 40 | return $string; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Convert UTF-8 strings to a different encoding. NB. The result |
|
| @@ 50-57 (lines=8) @@ | ||
| 47 | * @param string $to destination encoding |
|
| 48 | * @return string encoded string. |
|
| 49 | */ |
|
| 50 | public static function fromUTF8($string, $to) |
|
| 51 | { |
|
| 52 | if ($to != 'UTF-8') { |
|
| 53 | $s = iconv('UTF-8', $to, $string); |
|
| 54 | return $s !== false ? $s : $string; |
|
| 55 | } |
|
| 56 | return $string; |
|
| 57 | } |
|
| 58 | } |
|
| 59 | ||