PHP处理网页表单GET和POST方法
2013-07-05 18:17
549 查看
工作上的方便于是我写了这样的代码!
希望大家多多交流!
<?
/*
程序设计: 开源部落
made in beijing by 2013-06-28
QQ: 975555181
Email:phplo@w.cn
请勿删除该版权信息
用途:保留和修改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=2013&m=06
用了
<?=getplus('c','3')?>
之后显示
?method=1&a=1&b=2&y=2013&m=06&c=3
用了
<?=getplus('a','3','open')?>
之后显示
?method=1&b=2&y=2013&m=06&a=3
把a=3拖到最后面来了
我用
<?=getplus('a','','open')?>
来和javascript结合,上一页,自己感觉还是挺好的,可能还有写Bug没发现吧,希望大家多多提提!
本文原地址:http://www.phplo.com/php/1634.html
希望大家多多交流!
<?
/*
程序设计: 开源部落
made in beijing by 2013-06-28
QQ: 975555181
Email:phplo@w.cn
请勿删除该版权信息
用途:保留和修改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=2013&m=06
用了
<?=getplus('c','3')?>
之后显示
?method=1&a=1&b=2&y=2013&m=06&c=3
用了
<?=getplus('a','3','open')?>
之后显示
?method=1&b=2&y=2013&m=06&a=3
把a=3拖到最后面来了
我用
<?=getplus('a','','open')?>
来和javascript结合,上一页,自己感觉还是挺好的,可能还有写Bug没发现吧,希望大家多多提提!
本文原地址:http://www.phplo.com/php/1634.html
相关文章推荐
- PHP表单处理中GET与POST的区别
- PHP表单处理-GET与POST区别
- php表单中的get和post方法
- php使用fsockopen函数发送post,get请求获取网页内容的方法
- php使用fsockopen函数发送post,get请求获取网页内容的方法
- php fsockopen 伪造 post和get方法
- 表单 form 的 get/post 方法
- form表单中get方法和post方法的区别
- php发送get、post请求的几种方法
- PHP对表单提交特殊字符的过滤和处理方法汇总
- PHP中使用cURL实现Get和Post请求的方法
- php自定义类fsocket模拟post或get请求的方法
- 第二百五十八节,Tornado框架-逻辑处理get()方法和post()方法,初识模板语言
- HTTP协议与HTTP表单传输格式,再论get、post方法
- wininet进行网页的post与get方法。
- from 表单提交返回值用post或者是get方法实现
- 几种表单提交方法的总结及get与post的区别
- 两种HTTP方法服务器传送表单数据:GET和POST的区别
- php发送get和post的方法
- Nodejs GET 方法与POST 方法提交表单两个参数