|
使用$_GET[]接收URL参数escape解码中文字符串会出现解码错误,求助!
示例代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>查询页</title>
<script type="text/javascript">
//javascript接收Get方法的参数
//var programstr = request("program");
//document.write(programstr);
function request(strname){
var hrefstr,pos,parastr,para,tempstr;
if(arguments[1]!=null){
hrefstr = arguments[1];
}else{
hrefstr = window.location.href;
}
pos = hrefstr.indexOf("?");
parastr = hrefstr.substring(pos+1);
return GetUrlStrVar(parastr,strname);
}
//从QueryString字符串中取变量值
function GetUrlStrVar(UriString,CookieName){
var hrefstr,pos,para,tempstr,RetStr='';
if(UriString!=null && UriString!=undefined){
para = UriString.split("&");
for(var i=0;i<para.length;i++){
tempstr = para[i];
pos = tempstr.indexOf("=");
if(tempstr.substring(pos,0) == CookieName){
RetStr=tempstr.substr(pos+1,tempstr.length-pos-1);
}
}
}else{
RetStr="";
}
return Urldencoding(RetStr);
}
//将变量写入QueryString字符串中
function SetUrlStrVar(UriString,VarName,VarValue){
var hrefstr,pos,parastr,para,tempstr,RetStr;
para = UriString.split("&");
VarValue=Urlencoding(VarValue);
RetStr="";
if(UriString.indexOf(VarName)>=0){
for(var i=0;i<para.length;i++){
tempstr = para[i];
pos = tempstr.indexOf("=");
if(tempstr.substring(0,pos) == VarName){
if(VarValue!=''){
RetStr=RetStr + "&" + VarName + "=" + VarValue;
}
}else{
RetStr=RetStr+"&"+tempstr;
}
}
}else{
RetStr=UriString;
if(VarValue!=''){
RetStr=RetStr+"&"+VarName+"="+VarValue;
}
}
return ltrimVBcrlf(RetStr,"&");
}
//将Url字串转为Object
function UrlStr2Obj(UriString){
var pos,para,tempstr,RetStr=new Object,Var,Val,UriString;
if(UriString!=null && UriString!=undefined){
para = UriString.split("&");
for(var i=0;i<para.length;i++){
tempstr = para[i];
pos = tempstr.indexOf("=");
Var=tempstr.substring(pos,0);
Val=Urldencoding(tempstr.substr(pos+1,tempstr.length-pos-1));
if(Val=='')continue;
if(!isNaN(Number(Val))){
eval('RetStr.'+Var+'='+Val);
}else{
eval('RetStr.'+Var+'=\''+Val.replace(/'/ig,"\\'").replace(/\n/ig,"\\n")+'\'');
}
}
}
return RetStr;
}
function Urlencoding(){
return escape(arguments[0]);
}
function Urldencoding(){
return unescape(arguments[0]);
}
</script>
</head>
<body>
<form action="?" method="get">
<input name="test" type="text" size="10" />
<input type="submit" value="查询" />
<span style="margin-left:100px;"></span>
<input name="button" type="button" value="传值"/>
</form>
这个是静态页面的代码:
<?php
header('content-type:text/html;charset=utf-8');
$city=@$_GET['city']?$_GET['city']:'';
die($city);
?>
这个事php页面的代码,接收过来的$test是一些乱码,但是在传值过程中的url编码使用url编码解析器是可以解析的,编码方式为utf-8,这边输出的是一堆乱码,既不是gbk,gb2312,也不是utf-8,求救,这个后面可能用的会比较多,帮帮忙吧……
|
|