PHP实验

实验一

<?php
/**
* Created by PhpStorm.
* User: qichunlin
* Date: 2018/5/17
* Time: 下午5:35
*/ echo "请输入要排序的数字:<br/>";
echo "<form method=post>";
//循环生成文本框
for ($i = 1; $i < 6; $i++) {
//文本框的名字是数组名
echo "<input type='text' name='stu[]' size='5'>";
if ($i < 5) {
echo "-";
}
}
echo "<input type='submit' name='bt' value='提交'>";
echo "</form>";
if (isset($_POST['bt'])) {
$temp = 0;
$stu = $_POST['stu'];
$num = count($stu);
echo "您输入的数据有<br/>";
foreach ($stu as $score) {
echo $score . "<br>";
}
for ($i = 0; $i < $num; $i++)
for ($j = $i + 1; $j < $num; $j++) {
if ($stu[$i] > $stu[$j]) {
$temp = $stu[$i];
$stu[$i] = $stu[$j];
$stu[$j] = $temp;
} }
echo "排序后的数据如下所示:<br/>";
//使用while循环遍历数组
while (list($key, $value) = each($stu)) {
//输出排序后的数组
echo $value . "<br/>";
}
}
?>

实验二


<?php
/**
* Created by PhpStorm.
* User: qichunlin
* Date: 2018/5/17
* Time: 下午6:10
*/ echo "请输入学号:<br/>";
echo "<form method='post'>";
for ($i = 1; $i < 6; $i++) {
//文本框的名字就是数组名
echo "<input type='text' name='stu[]' size='6'>";
if ($i < 5)
echo "-";
}
echo "<input type='submit' name='bt' value='提交'>";
echo "</form>";
if (isset($_POST['bt'])) {
//echo "123";
$k = 0;
$jsj = array();
$stu = $_POST['stu'];
for ($i = 0; $i < count($stu); $i++)
for ($j = $i + 1; $j < count($stu); $j++) {
if (strcmp($stu[$i], $stu[$j] == 0))
array_splice($stu, $j, 1);
}
$str = implode(",", $stu);
echo "所有的学生学号如下:</br>";
echo $str . "<br>";
foreach ($stu as $value) {
if (strstr($value, "0811")) {
$string = str_replace("08121", "08110", $value);
$jsj[$k] = $string;
$k++; }
}
echo "计算机专业的学号如下:</br>";
echo implode(",", "$jsj");
}
?>

实验三

注册页面

-->
div {
text-align: center;
font-size: 24px;
color: #0000FF;
} table {
margin: 0 auto;
} </style>

用户注册
    <tr>
<td>出生日期:</td>
<td><input type="text" name="BIRTHDAY"></td>
<td class="STYLE1">* 有效的日期</td>
</tr> <tr>
<td>邮箱</td>
<td><input type="text" name="EMAIL"></td>
<td class="STYLE1">* 有效的邮件地址</td>
</tr> <tr>
<td colspan="3" align="center"><input type="submit" name="GO" value="注册">&nbsp;&nbsp;&nbsp;
<input type="reset" name="NO" value="取消">
</td>
</tr>
</table>

if (!$checkId)
echo "<script>alert('用户格式错误!')</script>";
else if (!$checkPwd)
echo "<script>alert('密码格式错误!')</script>";
else if (!$checkBirthday)
echo "<script>alert('出生日期格式错误!')</script>";
else if (!$checkEmail)
echo "<script>alert('Email格式错误!')</script>";
else
echo "注册成功!";

}

?>


###实验四

table, div, td {
text-align: center;
}
table {
margin: 0 auto;
}
p {
font-size: 18px;
color: #FF0000;
}

用户名: * 6~12个字符(数字、字母和下划线)
密码: * 6~20个数字
学号
姓名
成绩

注意,学号值不能重复

排序后的成绩表如下: