等同js脚本里的escape函数
null Core_Text::escape( string $str [, string $encode = string(5) "UTF-8" ] )
参数列表
参数 类型 描述 默认值 $str
string
$str $encode
string
$encode string(5) "UTF-8"
public static function escape($str, $encode = 'UTF-8')
{
$encode = strtoupper($encode);
if ( $encode == 'UTF-8' )
{
preg_match_all("/[\xC0-\xE0].|[\xE0-\xF0]..|[\x01-\x7f]+/", $str, $r);
}
else
{
preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/", $str, $r);
}
//prt($r);
$ar = $r[0];
foreach ( $ar as $k => $v )
{
$ord = ord($v[0]);
if ( $ord <= 128 )
{
$ar[$k] = rawurlencode($v);
}
else
{
$ar[$k] = "%u" . bin2hex(iconv($encode, "UCS-2BE", $v));
}
} //foreach
return join("", $ar);
}