用fetch_from_array()函数获取$_GET,$_POST数据,分解键对值


<?php
function fetch_from_array(&$arr,$index=null,$xss_clean=false)
{
	isset($index) or $index=array_keys($arr);
	
	if(is_array($index))
	{
		$output=array();
		foreach($index as $key)
		{
			
			$output[$key]=fetch_from_array($arr,$key,$xss_clean);
			
		}
		return $output;
	}
	if(isset($arr[$index]))
	{
		$value=$arr[$index];
		
	}
	elseif(($count=preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/',$index,$matches))>1)
	{
		$value=$arr;
		for($i=0;$i<$count;$i++)
		{
			$key=trim($matches[0][$i],'[]');
			if($key==='')
			{
				break;
			}
			
			if(isset($value[$key]))
			{
				$value=$value[$key];
			}else
			{
				return null;
			}
		}
	}else
	{
		return null;
	}
	return $value;
}

?>
//这个表格提交给fetch_from_array()函数
<html>
<meta http-equiv="content-type";content="text/html";charset="utf-8">
<head>
<title>测试GET提交</title>
</head>
<body>
<div>
<form id="form1" action="" method="get">
First Name&emsp;: <input type="text" name="fname"><br/>
Last  Name&emsp;: <input type="text" name="lname"><br/>
Password  &nbsp;&emsp;: <input type="password" name="pwd"><br/>
<div id="sub"><input type="submit" value="提交"></div>
</form>
</div>
</body>
</html>

//在本页输出从GET里获取到的数据
<?php 
$data=array();
$data=fetch_from_array($_GET,['fname','lname','pwd'],false);
echo implode(',',$data);

?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<?php $link=mysqli_connect("localhost","user","123456","database","3307"); if(!empty($_POST["tijiao"])) { //$sql="delete from xxnews where ID=".$_GET["dID"]; //$rs=mysqli_query($link,$sql); $title=$_POST["title"]; $author=$_POST["author"]; $newsDate=$_POST["newsDate"]; $source=$_POST["source"]; $content=$_POST["content"]; $sql="update from xxnews where ID=".$_POST["uID"]; $rs=mysqli_query($link,$sql); //$link=mysqli_connect("localhost","user","123456","database","3307"); // $sql="update xxnews set title='".$title."',author='".$author."',newsDate='".$newsDate."',source='".$source."',content='".$content."' where ID=".$_GET["uID"]; // $rs=mysqli_query($link,$sql); } ?> <div class="head1"> XX新闻中心 </div> <?php $link=mysqli_connect("localhost","user","123456","database","3307"); $sql="SELECT * FROM xxnews WHERE ID = ".$_POST["ID"]; $rs=mysqli_query($link,$sql); while($rows=mysqli_fetch_array($rs)) { echo "<form action='update.php?uID=".$rows["ID"]."' method='post' target='_blank'>"; echo "<div class='head2'>"; echo "标题:<input type='text' name='title' value='".$rows["title"]."' />"; echo "</div>"; echo "<div class='head3'>"; echo "作者:<input type='text' name='author' value='".$rows["author"]."' />       "; echo "时间:"; date_default_timezone_set('PRC'); echo "<input type='text' name='newsDate' value='".date('Y-m-d', time())."' />"; echo "        来源:<input type='text' name='source' value='".$rows["source"]."' />       <input type='submit' name='tijiao' value='修改新闻' class='tijiao' />"; echo "</div>"; echo "<div class='content'>"; echo "<textarea class='content1' name='content'>"; echo $rows["content"]; echo "</textarea>"; echo "</div>"; echo "</form>"; } ?> <div class="footer"> XX新闻<br /> 地址:广东省肇庆市端州区广东工商职业技术大学星湖校区<br /> 电话:123456789 </div>这段代码有什么问题
06-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值