php - Convert single byte string to double byte string
Get the solution ↓↓↓I want the stringGame
to convertпј§пЅЃпЅЌпЅ…
. This string is a Japanese double byte string.
Is it possible to achieve this using PHP? If so, how?
Answer
Solution:
First of all,пј§пЅЃпЅЌпЅ…
is not ASCII charset, so you might need to set the pageContent-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пј§пЅЃпЅЌпЅ…
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
Answer
Solution:
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 ofmb_convert_encoding
for you.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: foreign key constraint is incorrectly formed laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.