In PHP, converting Shift-JIS into UTF-8

php

Still some websites use Shift-JIS character sets instead of UTF-8. To convert Shift-JIS Japanese text into a more friendly UTF-8 format, I needed to include the following in my PHP code:

$converted_string = iconv(‘shift-jis‘,’utf-8‘.’//TRANSLIT’,$string_to_convert);

Of course it’s also possible to store the data in MySQL using a BLOB data type, but I wanted to use standard text/varchar, and make it searchable. This worked well.

The same can also be applied for converting the other way, when needing to convert UTF-8 to Shift_JIS.

$converted_string = iconv(‘utf8‘,’shift-jis‘.’//TRANSLIT’,$string_to_convert);

Leave a Reply

Your email address will not be published. Required fields are marked *