Convert single byte string to double byte string

2019-03-27 15:10发布

I want the string Game to convert Game. This string is a Japanese double byte string.

Is it possible to achieve this using PHP? If so, how?

3条回答
干净又极端
2楼-- · 2019-03-27 15:37

First of all, Game is not ASCII charset, so you might need to set the page Content-type header to see a proper output:

header("Content-type: text/html; charset=utf-8");

Then you can convert it using this function

echo mb_convert_kana('Game', "R", 'UTF-8')

EDIT:

For MySQL I couldn't find a converter to do the same. However, you can still convert it manually on the Hex level, for example, you can get the word Game like this

SELECT CHAR(0xefbca7, 0xefbd81, 0xefbd8d, 0xefbd85) as `Full Width`;

So, we can just write a mapping function in MySQL that replaces the characters using this table

查看更多
时光不老,我们不散
3楼-- · 2019-03-27 15:40

Well, can't say for sure whether I got your question right, but the following console one-liner:

$ php -r 'var_dump(mb_convert_encoding("Game", "UCS-2"));'

gives me the following:

string(8) "\000G\000a\000m\000e"

Is this what you want? As Mark Baker already said, it's just the case of mb_convert_encoding for you.

查看更多
别忘想泡老子
4楼-- · 2019-03-27 15:50

you can try for this function mb_convert_kana

查看更多
登录 后发表回答