其他分享
首页 > 其他分享> > 是否经过urlencode

是否经过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; }

 

标签:urlencode,false,经过,是否,substr,strpos,str,needEncode,encoded
来源: https://www.cnblogs.com/lvjiefly/p/12834615.html