Heim  >  Artikel  >  Backend-Entwicklung  >  PHP程序处理网页表单的GET和POST方法另外用法_PHP教程

PHP程序处理网页表单的GET和POST方法另外用法_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:36:22732Durchsuche

有时候我们需要保留GET和POST参数在下一页或者其他用途上传递!
工作上的方便于是我写了这样的代码!
希望大家多多交流!


/*
程序设计: 林建炫(飘枫设计室)
made in 珠海 by 2007-03-24
QQ: 5818500
Email:linzhenxuan@163.com
请勿删除该版权信息
用途:保留和修改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;
}
?>

比如原来
GET: ?method=1&a=1&b=2
POST: y=2007&m=03
用了
=getplus(c,3)?>
之后显示
?method=1&a=1&b=2&y=2007&m=03&c=3
用了
=getplus(a,3,open)?>
之后显示
?method=1&b=2&y=2007&m=03&a=3
把a=3拖到最后面来了
我用=getplus(a,,open)?>来和javascript结合
上一页
自己感觉还是挺好的!
可能还有写Bug没发现吧!
希望大家多多提提!

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/508239.htmlTechArticle有时候我们需要保留GET和POST参数在下一页或者其他用途上传递! 工作上的方便于是我写了这样的代码! 希望大家多多交流! ? /* 程序设计...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn