php逐一处理字符串里的中文字符函数
将字符串中中文字符编码后16进制字符小写:
function urlencode_lower($str) {
$outStr = '';
$len = strlen($str);
for($i = 0; $i < $len; $i++) {
if(ord($str{$i}) > 127) {
$ch = substr($str, $i, 2);
$p = 1;
$outStr .= strtolower(urlencode($ch));
} else {
$ch = substr($str, $i, 1);
$p = 0;
$outStr .= urlencode($ch);
}
$i += $p;
}
return $outStr;
}
echo urlencode_lower('妈妈咪'); //%c2%e8%c2%e8%df%e4