* @package Mammut\Locale */ class Encoding extends \Mammut\StdObject { const E_ASCII = 'ascii'; const E_ANSI = 'ansi'; const E_UTF8 = 'uft8'; const E_UTF16 = 'uft16'; const E_UCS2 = 'ucs2'; const E_UCS2LE = 'ucs2le'; const E_ISO8859_1 = 'iso88591'; const E_LATIN1 = 'iso88591'; /** * Codepage 1252 aka Windows Western European */ const E_CP1251 = 'win1251'; private $type; public function __construct($type = NULL) { $this->setType($type); } public function getType() { return $this->type; } public function setType($type) { $this->type = $type; } public static function transcode($input, $from, $to) { if (extension_loaded('mbstring')) return self::transcode_mbstring($input, $from, $to); trigger_error('no trascoding support found', E_WARNING); return $input; } private static function toMBMethodType($input) { switch ($input) { case self::E_UTF8: return 'UTF-8'; case self::E_UCS2: return 'UCS-2'; case self::E_UCS2LE: return 'UCS-2LE'; } return $input; } private static function transcode_mbstring($input, $from, $to) { $from = self::toMBMethodType($from); $to = self::toMBMethodType($to); return mb_convert_encoding($input, $to, $from); } }