加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP解密Unicode及Escape加密字符串

发布时间:2020-12-12 20:53:32 所属栏目:PHP教程 来源:网络整理
导读:本文给大家分享一个PHP解密Unicode及Escape加密字符串函数 function unicode2utf8($c) { $str=""; if ($c 0x80) { $str.=chr($c); } else if ($c 0x800) { $str.=chr(0xc0 | $c6); $str.=chr(0x80 | $c 0x3f); } else if ($c 0x10000) { $str.=chr(0xe0 | $c

本文给大家分享一个PHP解密Unicode及Escape加密字符串函数

function unicode2utf8($c) {
$str="";
if ($c < 0x80) {
$str.=chr($c);
} else if ($c < 0x800) {
$str.=chr(0xc0 | $c>>6);
$str.=chr(0x80 | $c & 0x3f);
} else if ($c < 0x10000) {
$str.=chr(0xe0 | $c>>12);
$str.=chr(0x80 | $c>>6 & 0x3f);
$str.=chr(0x80 | $c & 0x3f);
} else if ($c < 0x200000) {
$str.=chr(0xf0 | $c>>18);
$str.=chr(0x80 | $c>>12 & 0x3f);
$str.=chr(0x80 | $c>>6 & 0x3f);
$str.=chr(0x80 | $c & 0x3f);
}
return $str;
}

$str='%u5927%u5BB6%u597D%uFF0C我是孤魂!
u8FD9u662Fu6D4Bu8BD5u6587u672CuFF01';
echo uni_decode($str); // 大家好,我是孤魂!这是测试文本!

在网上搜索一把,很多用php实现的escape函数,大同小异

$v){ if(ord($ar[$k])>=127){ $tmpString=bin2hex(iconv("GBK","ucs-2",$v)); if (!eregi("WIN",PHP_OS)){ $tmpString = substr($tmpString,2,2).substr($tmpString,2); } $reString.="%u".$tmpString; } else { $reString.= rawurlencode($v); } } return $reString; }

以上所述就是本文的全部内容了,希望大家能够喜欢。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读