Convert a single byte string to a two byte string

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

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

+7
php encoding unicode
source share
3 answers

First of all, Game not ASCII encoded, so you may need to set the Content-type page title to see the correct 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 could not find a converter to do the same. However, you can convert it manually at the Hex level, for example, you can get the word Game as follows

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

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

+5
source share

Well, I can’t say for sure whether I received your question correctly, but the following console is single-line:

 $ 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, this is just the mb_convert_encoding case for you.

0
source share

you can try this function mb_convert_kana

-one
source share

All Articles