2

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?

SuHun Han
  • 65
  • 7

3 Answers3

4

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.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
1

It would be easier to use mb_convert_kana:

$string = 'Characters: Game';
$newString = mb_convert_kana($string,'a');
Hygison Brandao
  • 590
  • 1
  • 4
  • 16
0

I'm sure there is a much easier answer but couldnt you make a dictonary object with the special charter as the key and the char you want as the value

then just do a simple find and replace?

Crash893
  • 11,428
  • 21
  • 88
  • 123
  • 1
    I can't replace those characters.. Include japanese, english, numbers, special chars(★, ☆ and others)... – SuHun Han Feb 08 '13 at 16:33
  • I assumed that "Transform" was to look up and replace the unwanted char with the wanted equivalent – Crash893 Feb 08 '13 at 17:01