欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

escape unescape的php下的实现方法_PHP教程

程序员文章站 2022-04-22 22:01:49
...
function escape($str) {
preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(ord($v[0]) $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);
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/318353.htmlTechArticlefunctionescape($str){ preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r); $ar=$r[0]; foreach($aras$k=$v){ if(ord($v[0])128) $ar[$k]=rawurlencode($v); else $ar[$k]="%u".bin2hex(ic...