<?php /** * unicode解码 * @param $str * @return mixed|string */ function unicode_decode($name) { $result = ''; $json = '{"str":"' . $name . '"}'; $arr = json_decode($json, true); if (!empty($arr)) { $result = $arr['str']; } return $result; } //字符串按照文字长度分割成数组 function str_split_unicode($str, $length = 0) { if ($length > 0) { $ret = array(); $len = mb_strlen($str, "UTF-8"); for ($i = 0; $i < $len; $i += $length) { $ret[] = mb_substr($str, $i, $length, "UTF-8"); } return $ret; } return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY); } //转成标准的unicode编码 function stardand_unicode($chinese) { $arr = str_split_unicode($chinese, 4); $res = array_map(function ($value) { return '\u' . $value; }, $arr); return implode('', $res); } /** * unicode编码 * @param $str * @return string */ function unicode_encode($chinese) { $result = json_encode($chinese); return strtoupper(str_replace(['"', '"', '\u'], "", $result)); } echo "<pre>"; echo unicode_encode('测试接收短信')."<br/>"; print_r(unicode_decode(stardand_unicode('6D4B8BD563A5653677ED4FE1'))); echo "</pre>";这个也是 串口的文本模式标准
中文加密 文本模式
加中文字符串加密成漂亮的字母
猜你喜欢
转载自hudeyong926.iteye.com/blog/2383479
今日推荐
周排行