用javascript对URL进行编码时有3个函数可选:escape,encodeURI,encodeURIComponent函数.下面介绍一下它们的用法和区别。
1、 传递参数时需要使用encodeURIComponent,这样组合的url才不会被#等特殊字符截断。
例如:
<script language="javascript">document.write(''<a href="http://www.phpzixue.cn/?logout&aid=7&u=''+encodeURIComponent("http://www.phpzixue.cn/")+''">退出</a>'');</script>
2、 进行url跳转时可以整体使用encodeURI
例如: Location.href=encodeURI(http://cang.baidu.com/do/s?word=中国asp之家&ct=21);
3、...
<?
/**
* 将字符串转换成unicode编码
*
* @param string $input
* @param string $input_charset
* @return string
*/
function str_to_unicode($input, $input_charset = 'gbk'){
$input = iconv($input_charset, "gbk", $input);
preg_match_all("/[x80-xff]?./", $input, $ar);
$b = array_map('utf8_unicode_', $ar[0]);
$outstr = join("", $b);
return $outstr;
}
function utf8_unicode_($c, $input_charset = 'gbk'){
$c = iconv($input_charset, 'utf-8', $c);
return utf8_unicode($c);
}
// utf...