. */ /** * Class ShiftJisConverter * Includes functions to convert UTF8 strings to Shift JIS (Japanese) */ class ShiftJisConverter { // The code number of Japanese two-byte character "ー" is separated by Japanese encoding types. // Hyphen, Centered dot var $utf_escape_patterns_search = array('/\xE2\x80\x93/', '/\xE2\x80\xA2/'); var $utf_escape_patterns_replace = array("\xE2\x88\x92", "\xE3\x83\xBB"); /** * Convert Shift-JIS (Standard Encoding for Japanese Applications) to UTF-8. * @param $str string * @return string */ public function convertUtf8ToSjis($str) { return mb_convert_encoding($this->replaceShiftjisEscapeChars($str), 'SJIS-win', 'utf-8'); } public function replaceShiftjisEscapeChars($str) { return preg_replace( $this->utf_escape_patterns_search, $this->utf_escape_patterns_replace, $str); } public function getContentTypeCharSet() { return 'Shift_JIS'; } public function canConvert() { // If mb_convert_encoding function is not enabled (mb_string module is not installed), // then converting cannot be done. return function_exists('mb_convert_encoding'); } }