escape编码 和 unescape解码
程序员文章站
2022-05-25 11:26:03
...
php代码
function escape($str) { $sublen = strlen ( $str ); $retrunString = ""; for($i = 0; $i < $sublen; $i ++) { if (ord ( $str [$i] ) >= 127) { $tmpString = bin2hex ( iconv ( "gb2312", "ucs-2", substr ( $str, $i, 2 ) ) ); $retrunString .= "%u" . $tmpString; $i ++; } else { $retrunString .= "%" . dechex ( ord ( $str [$i] ) ); } } return $retrunString; } function unescape($str) { $str = rawurldecode ( $str ); preg_match_all ( "/%u.{4}|&#x.{4};|&#\d+;|.+/U", $str, $r ); $ar = $r [0]; foreach ( $ar as $k => $v ) { if (substr ( $v, 0, 2 ) == "%u") $ar [$k] = iconv ( "UCS-2", "GBK", pack ( "H4", substr ( $v, - 4 ) ) ); elseif (substr ( $v, 0, 3 ) == "&#x") $ar [$k] = iconv ( "UCS-2", "GBK", pack ( "H4", substr ( $v, 3, - 1 ) ) ); elseif (substr ( $v, 0, 2 ) == "&#") { $ar [$k] = iconv ( "UCS-2", "GBK", pack ( "n", substr ( $v, 2, - 1 ) ) ); } } return join ( "", $ar ); }
上一篇: php,button传值的有关问题
下一篇: Python学习笔记之常用函数及说明
推荐阅读
-
C#版的 Escape() 和 Unescape() 函数分享
-
day06-is和==以及编码解码
-
python bytes和bytearray、编码和解码
-
C#版的 Escape() 和 Unescape()
-
js的字符串加密/javascript字符编码 escape,urlencode等使用asp解密或者解码
-
php 正确解码javascript中通过escape编码后的字符
-
如何使用PHP实现javascript的escape和unescape函数
-
php 正确解码javascript中通过escape编码后的字符
-
registerstartupscript php 正确解码javascript中通过escape编码后的字符
-
registerstartupscript php 正确解码javascript中通过escape编码后的字符