Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an japanese english character. This character is not normal english string.

Characters: Game

How to transform this character to normal english character in php?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

Subtract 65248 from the ordinal value of each character. In other words:

$str = "Game some other text by ヴィックサ";
$str = preg_replace_callback(
    "/[x{ff01}-x{ff5e}]/u",
    function($c) {
        // convert UTF-8 sequence to ordinal value
        $code = ((ord($c[0][0])&0xf)<<12)|((ord($c[0][1])&0x3f)<<6)|(ord($c[0][2])&0x3f);
        return chr($code-0xffe0);
    },
    $str);

This will replace all of the "Fullwidth" characters with their normal width equivalents.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...