function escape($str) {
preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(ord($v[0]) < 128)
$ar[$k] = rawurlencode($v);
else
$ar[$k] = "%u".bin2hex(iconv("GB2312","UCS-2",$v));
}
return join("",$ar);
}
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|.+/",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u" && strlen($v) == 6)
$ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,-4)));
}
return join("",$ar);
}
您可能感兴趣的文章:php中json_encode不兼容JSON_UNESCAPED_UNICODE的解决方案PHP实现Javascript中的escape及unescape函数代码分享如何使用PHP实现javascript的escape和unescape函数php模拟js函数unescape的函数代码js中的escape及unescape函数的php实现代码PHP实现JS中escape与unescape的方法
escape
方法
PHP