如何将日语英语字符转换为正常英语字符? [英] how to transform japanese english character to normal english character?

查看:179
本文介绍了如何将日语英语字符转换为正常英语字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日语英语字符。
此字符不是正常的英文字符串。

 字符:游戏



如何在 php 中将此字符转换为正常英文字符?

解决方案

从每个字符的序数值中减去65248。换句话说:

  $ str =ヴィックサ游戏一些其他文字; 
$ str = preg_replace_callback(
/ [\x {ff01} -\x {ff5e}] / u,
function($ c){
//将UTF-8序列转换为序数值
$ code =((ord($ c [0] [0])& 0xf)<& ])& 0x3f)<< 6)|(ord($ c [0] [2])& 0x3f);
return chr($ code-0xffe0);
} b $ b $ str);

这将用它们的正常宽度等值替换所有的Fullwidth字符。


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?

解决方案

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.

这篇关于如何将日语英语字符转换为正常英语字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆