/**
* php 实现js escape 函数
* @param [type] $string [description]
* @param string $encoding [description]
* @return [type] [description]
*/
function escape($string, $encoding = 'UTF-8'){
$return = null;
for ($x = 0; $x < mb_strlen($string, $encoding);$x ++)
{
$str = mb_substr($string, $x, 1, $encoding);
if (strlen($str) > 1) { // 多字节字符
$return .= "%u" . strtoupper(bin2hex(mb_convert_encoding($str, 'UCS-2', $encoding)));
} else {
$return .= "%" . strtoupper(bin2hex($str));
}
}
return $return;
}
php 实现js escape 函数
最新推荐文章于 2024-05-03 23:27:58 发布