是否经过urlencode

 
function isUrlEncoded($str) 
{ $str = strtoupper($str); $dontNeedEncoding = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789-_.";
 $encoded = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $needEncode = false;
 for ($i = 0; $i < strlen($str); $i++) { $c = substr($str, $i, 1);
 if (strpos($dontNeedEncoding, $c) !== false) {

//不需要处理 
continue; } if ($c == '%' && ($i + 2) < strlen($str)) { 

// 判断是否符合urlEncode规范 
$c1 = substr($str, ++$i, 1); $c2 = substr($str, ++$i, 1); if (strpos($encoded, $c1) !== false && strpos($encoded, $c2) !== false) { continue; } } 

// 其他字符,肯定需要
urlEncode $needEncode = true; break; } 

//如果有字符需要进行编码,那这个字符串肯定就是没有经过编码的 
return !$needEncode; }

 

posted @ 2020-05-06 09:57  景北斗  阅读(229)  评论(0编辑  收藏  举报