PHP版 escape加密和unescape解密
php 版 模仿 js ,unescape函数解码,escape函数编码的方法
escape加密:
function escape($string, $in_encoding = 'UTF-8',$out_encoding = 'UCS-2') { $return = ''; if (function_exists('mb_get_info')) { for($x = 0; $x < mb_strlen ( $string, $in_encoding ); $x ++) { $str = mb_substr ( $string, $x, 1, $in_encoding ); if (strlen ( $str ) > 1) { // 多字节字符 $return .= '%u' . strtoupper ( bin2hex ( mb_convert_encoding ( $str, $out_encoding, $in_encoding ) ) ); } else { $return .= '%' . strtoupper ( bin2hex ( $str ) ); } } } return $return; }
unescape解密:
function unescape($str) { $ret = ''; $len = strlen($str); for ($i = 0; $i < $len; $i ++) { if ($str[$i] == '%' && $str[$i + 1] == 'u') { $val = hexdec(substr($str, $i + 2, 4)); if ($val < 0x7f) $ret .= chr($val); else if ($val < 0x800) $ret .= chr(0xc0 | ($val >> 6)) . chr(0x80 | ($val & 0x3f)); else $ret .= chr(0xe0 | ($val >> 12)) . chr(0x80 | (($val >> 6) & 0x3f)) . chr(0x80 | ($val & 0x3f)); $i += 5; } else if ($str[$i] == '%') { $ret .= urldecode(substr($str, $i, 3)); $i += 2; } else $ret .= $str[$i]; } return $ret; }
全能资源库丨本站资源除特殊声明外,均来自于网络收集整理仅供学习研究,如需商业使用请获得作者商业授权,如果侵犯了您的合法权益,请联系我们的投诉邮箱:qinglikf@163.com,我们将在24小时内删除!如有其它疑问请联系在线客服(微信公众号:轻狸团队 丨菜单栏人工客服)特别注意:访问本站即同意本站《免责声明&版权声明》,本站原创内容未经授权禁止转载!
全能资源库 » PHP版 escape加密和unescape解密
全能资源库 » PHP版 escape加密和unescape解密