php中怎么利用表单请求获得数据,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
request.php
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8;" />
<title>计算请求</title>
</head>
<body>
<form action="result.php" method="post">
<input type="text" name="grade"/>
<input type="submit" value="开始计算"/>
</form>
</body>
</html>
[code]
result.php
[code]
<?php
$grade=$_REQUEST['grade'];//grade-->和表单中的name值一样
$arr=explode(" ",$grade);//以空格拆分字符串,并得到数组结果
print_r($arr);
$res=0;
for($i=0;$i<count($arr);$i++){
$res+=$arr[$i];
}
echo "<br/>ALL=".$res;
echo "<br/>AVG=".(round($res/count($arr),0));//round(12.334,2)//四舍五入的方法
?>看完上述内容,你们掌握php中怎么利用表单请求获得数据的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注天达云行业资讯频道,感谢各位的阅读!