NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
| unicode字符转换 | | | --- | --- | ``` /** * [fullToHalf 全角转半角] * @param [type] $str [需要转换的字符串] * @return [type] [description] */ function fullToHalf($str){ return preg_replace( // 全角字符 '/[\x{3000}\x{ff01}-\x{ff5f}]/ue', // 编码转换 // 0x3000是空格,特殊处理,其他全角字符编码-0xfee0即可以转为半角 '($unicode=char2Unicode(\'\0\')) == 0x3000 ? " " : (($code=$unicode-0xfee0) > 256 ? unicode2Char($code) : chr($code))', $str ); } /** * [halfToFull 半角转全角] * @param [type] $str [description] * @return [type] [description] */ function halfToFull($str){ return preg_replace( // 半角字符 '/[\x{0020}\x{0020}-\x{7e}]/ue', // 编码转换 // 0x0020是空格,特殊处理,其他半角字符编码+0xfee0即可以转为全角 '($unicode=char2Unicode(\'\0\')) == 0x0020 ? unicode2Char(0x3000) : (($code=$unicode+0xfee0) > 256 ? unicode2Char($code) : chr($code))', $str ); } ```