$str = "这是一个测试";
function escapeToHex($string, $encoding = "UTF-8") {
$r_str = "";
for ($x = 0; $x < mb_strlen($string, $encoding); $x ++) {
$str = mb_substr($string, $x, 1, $encoding);
if (strlen($str) > 1) {
$r_str .="%u".strtoupper(bin2hex(mb_convert_encoding($str, "UCS-2", $encoding)));
} else {
$r_str .="%". strtoupper(bin2hex($str));
}
}
return $r_str;
}
$str = preg_replace("/(%u)(\w{4})/i","$2;",escapeToHex($str));
print $str;
?>
阅读(904) | 评论(0) | 转发(0) |