EX2.5-1.php
<! DOCTYPE html>
<html>
<head>
<title>面积计算</title>
</head>
<body>
<!--产生POST外部变量的HTML5表单form1-->
<form action="" method="post">
请输入圆的半径: <input type="text" name="R"><br>
<input type="submit" name="postmethod" value="POST方法提交"/><br>
</form>
<!--产生POST外部变量的HTML5表单form2-->
<form action="" method="get">
请输入梯形的上底: <input type="text" name="A"><br>
请输入梯形的下底:<input type="text" name="B"><br>
请输入梯形的高:<input type="text" name="H"><br>
<input type="submit" name="getmethod" value="GET方法提交">
</form>
</body>
</html>
<?php
define("PI",3.1415926);
if(isset($_POST['postmethod'])) {
$r = $_POST['R'];
$C_area = PI * $r * $r;
echo "接收POST变量:<br>";
echo "圆的面积为:" . $C_area . "<br>";
}
if(isset($_GET['getmethod'])){
$a = $_GET['A'];
$b = $_GET['B'];
$h = $_GET['H'];
$T_area = ($a + $b) * $h/2.0;
echo "<br/>接收GET变量:<br/>";
echo "梯形面积为:".$T_area."<br/>";
}
?>
EX3.5-1.php
<form action="" method="post">
以下属于Web开发语言的有哪几种? <br>
<input type="checkbox" name="answer[]" value="C语言">C语言<br>
<input type="checkbox" name="answer[]" value="PHP">PHP<br>
<input type="checkbox" name="answer[]" value="FLASH">FLASH<br>
<input type="checkbox" name="answer[]" value="ASP">ASP<br>
<input type="checkbox" name="answer[]" value="JSP">JSP<br>
<input type="submit" name="bt_answer" value="提交"/>
</form>
<?php
if (isset($_POST['bt_answer'])){
$answer = @$_POST['answer'];
if (!$answer){
echo "<script>alert('请选择答案')</script>";
}
$num = count($answer);
$anw = "";
for ($i=0;$i<$num;$i++){
$anw = $anw.$answer[$i];
}
if ($anw == "PHPASPJSP"){
echo "<script>alert('回答正确')</script>";
}else{
echo "<script>alert('回答错误')</script>";
}
}
EX4.4-1.php
<html>
<body>
<form method="post">
<table align="center">
<tr><td>简单的计算器</td></tr>
<tr><td>
<input type="text" size="4" name="number1">
<select name="caculate">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" size="4" name="number2">
<input type="submit" name="ok" value="计算">
</td></tr>
</table>
</form>
</body>
</html>
<?php
function calc($a, $b, $caculate){
if ( $caculate == "+") return $a + $b;
if ( $caculate == "-") return $a - $b;
if ( $caculate == "*") return $a * $b;
if ( $caculate == "/") {
if ( $b == "0"){
echo "除数不能为0";
}else{
return $a / $b;
}
}
}
if (isset( $_POST['ok'])){
$number1 = $_POST['number1'];
$number2 = $_POST['number2'];
$caculate = $_POST['caculate'];
if (is_numeric($number1) && is_numeric($number2)){
$answer = calc($number1, $number2, $caculate);
echo "<script>alert('".$number1.$caculate.$number2."=".$answer."')</script>";
}else{
echo "<script>alert('输入的不是数字!')</script>";
}
}
EX-5.7-1.php
<!DOCTYPE html>
<style type="text/css">
table,div,td{
text-align: center;
}
table{
margin: 0 auto;
}
p{
font-size: 18px;
color:
}
</style>
<form name="fr1" method="post">
<table border="1">
<tr>
<td><div>学号</div></td>
<td><div>姓名</div></td>
<td><div>成绩</div></td>
</tr>
<?php
for($i=0;$i<5;$i++) {
?>
<tr>
<td><input type="text" name="XH[]"/></td>
<td><input type="text" name="XM[]"/></td>
<td><input type="text" name="CJ[]"/></td>
</tr>
<?php } ?>
<tr>
<td colspan="3"><input type="submit" name="bt_stu" value="提交" /></td>
</tr>
</table>
</form>
<p align="center">注意:学号值不能重复</p>
<!--以上是输入表单-->
<?php
if(isset($_POST['bt_stu']))
{
$XH = $_POST['XH'];
$XM = $_POST['XM'];
$CJ = $_POST['CJ'];
array_multisort($CJ,$XH,$XM);
for($i=0;$i<count($XH);$i++)
$sum[$i] = array($XH[$i],$XM[$i],$CJ[$i]);
echo "<div>排序后成绩表如下:</div>";
echo "<table border=2><tr><td>学号</td><td>姓名</td><td>成绩</td>";
foreach($sum as $value) {
list($stu_number,$stu_name,$stu_score) = $value;
echo "<tr><td>$stu_number</td><td>$stu_name</td><td>$stu_score</td>";
}
echo "</table><br>";
reset($sum);
while(list($key,$value) = @each($sum)) {
list($stu_number,$stu_name,$stu_score)=$value;
if($stu_number == "081101"){
echo "<p align=center>";
echo $stu_number."的姓名为:".$stu_name.",";
echo "成绩为:".$stu_score;
break;
}
}
}
?>
homework.php
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>提交PHP文件</title>
</head>
<body>
<form method="post" enctype="multipart/form-data" action="uploadfile.php">
<p align="center"><b>欢迎使用PHP程序设计作业上交系统</b></p>
PHP程序设计作业文件(*.php):
<input type="file" name="up_file"><br>
<input type="submit" value="上交" name="B1">
<input type="reset" value="取消" name="B2">
</form>
</body>
</html>
uploadfile.php
<?php
header("Content-Type:text/html;charset=utf-8");
if (!empty( $_FILES["up_file"]["name"])){
$file_name = $_FILES["up_file"]["tmp_name"];
$destination="./".$_FILES["up_file"]["name"];
if ( $_FILES["up_file"]["size"] > 1000000){
echo "文件太大";
}else {
move_uploaded_file( $file_name, $destination);
echo "<textarea rows=10 name=S1 cols=80 style='font-size:12pt';>",
file_get_contents( $destination);
echo "</textarea>";
}
}
cal.php
<?php
$year=@$_GET['year'];
$month=@$_GET['month'];
if(empty($year))
$year=@date("Y");
if(empty($month))
$year=@date("n");
$day=@date("j");
$wd_ar=array("日","一","二","三","四","五","六");
$wd=@date("w",mktime(0,0,0,$month,1,$year));
$y_lnk1 = $year <= 1970? $year = 1970 : $year - 1;
$y_lnk2 = $year >= 2037? $year = 2037 : $year + 1;
$m_lnk1 = $month <= 1? $month = 1 : $month - 1;
$m_lnk2 = $month >= 12? $month = 12 : $month + 1;
echo "<table cellpadding=6 cellspacing=0 width=200 bgcolor=#eeeeee ><tr align=center bgcolor=#cccccc>";
echo "<td colspan=4><a href='cal.php?year=$y_lnk1&month=$month'><</a>".$year."年<a href='cal.php?year=$y_lnk2&month=$month'>></a></td>";
echo "<td colspan=3><a href='cal.php?year=$year&month=$m_lnk1'><</a>".$month."月<a href='cal.php?year=$year&month=$m_lnk2'>></a></td></tr>";
echo "<tr align=center>";
for ( $i = 0;$i < 7; $i++){
echo "<td>$wd_ar[$i]</td>";
}
echo "</tr>";
$tnum = $wd + @date("t",@mktime(0,0,0,$month,1,$year));
for ( $i=0; $i<$tnum; $i++){
$date = $i + 1 - $wd;
if ($i%7 == 0) echo "<tr align=center>";
echo "<td>";
if ($i >= $wd){
if ($date == $day && $month == @date("n")){
echo "<b>".$day."</b>";
}else {
echo $date;
}
}
echo "</td>";
if ($i%7 == 6) echo "</tr>";
}
echo "</table>";