#33793 [Asn->Fbk]: Mojibake produced when converting utf-8 to sjis with certain characters

From: Date: Thu, 21 Jul 2005 10:47:30 +0000
Subject: #33793 [Asn->Fbk]: Mojibake produced when converting utf-8 to sjis with certain characters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-82266@lists.php.net to get a copy of this message
ID: 33793 Updated by: sniper@php.net Reported By: lars dot jensen at careercross dot com -Status: Assigned +Status: Feedback Bug Type: mbstring related Operating System: FreeBSD 5.3 PHP Version: 5.0.3 Assigned To: moriyoshi New Comment: Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip Previous Comments: ------------------------------------------------------------------------ [2005-07-21 10:19:24] tony2001@php.net Assigned to the maintainer. ------------------------------------------------------------------------ [2005-07-21 03:19:47] lars dot jensen at careercross dot com Description: ------------ Writing a class to handle conversion of UTF-8 input into SJIS using usual $body = mb_convert_encoding($body, "SJIS", "UTF-8"); function, usually works, but so far by testing, I identified three kanji's which makes this function fail to convert these correctly and thus causing mojibake The three UTF-8 characters is identified as follows chr(227).chr(136).chr(177) chr(227).chr(136).chr(178) chr(227).chr(136).chr(185) which in SJIS corresponds to chr(135).chr(138) chr(135).chr(139) chr(135).chr(140) Reproduce code: --------------- I created a "quick'n'dirty" solution as follows, which surely isnt optimal $body = str_replace(chr(227).chr(136).chr(177), '#mojihack1#', $body); $body = str_replace(chr(227).chr(136).chr(178), '#mojihack2#', $body); $body = str_replace(chr(227).chr(136).chr(185), '#mojihack3#', $body); $body = mb_convert_encoding($body, "SJIS", "UTF-8"); $body = str_replace('#mojihack1#', chr(135).chr(138), $body); $body = str_replace('#mojihack2#', chr(135).chr(139), $body); $body = str_replace('#mojihack3#', chr(135).chr(140), $body); ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33793&edit=1

« previous php.bugs (#82266) next »