有時候我們需要保留GET和POST參數在下一頁或者其他用途上傳遞!
工作上的方便於是我寫了這樣的代碼!
希望大家多多交流!
<?
/*
程序設計: 林建炫(飄楓設計室)
made in 珠海 by 2007-03-24
QQ: 5818500
Email: [email protected]
請勿刪除該版權信息
用途:保留和修改GET和POST參數
*/
Function getplus($x='',$value='',$plus='close',$method='all')
{
Global $_GET,$_POST;
$array = array();
if($method=='all')
{$array[] = $_GET;$array[] = $_POST;}
elseif($method=='get'){$array[] = $_GET;}
elseif($method=='post'){$array[] = $_POST;}
$a = $_GET;
$i = 1;
$true = 0;
foreach($array as $k => $a)
{
foreach($a as $b => $c)
{
if($b==$x)
{
$c = $value;
$true = 1;//找到啦
$true2 = 1;
}
if($plus=='close')
{
if($i==1)
{
$temp .= "?$b=$c";
}
else
{
$temp .= "&$b=$c";
}
}
else
{
if($i==1)
{
if($true2!=1){$temp .= "?$b=$c";}else{$temp.="?";unset($true2);}
}
else
{
if($true2!=1){$temp .= "&$b=$c";}else{unset($true2);}
}
}
$i++;
}
}
if($true==0)
{
if (strpos($temp,"?")>0 || strpos($temp,"=")>0)
{
$temp .= "&$x=$value";
}
else
{
$temp .= "?$x=$value";
}
}
elseif($true==1 && $plus!='close')
{
if (strpos($temp,"?")>0 || strpos($temp,"=")>0)
{
$temp .= "&$x=$value";
}
else
{
$temp .= "?$x=$value";
}
}
return $temp;
}
?>