<!DOCTYPE html>
<!--HTML5表单-->
<meta charset="UTF-8">
<style type="text/css">
table,div,td{
text-align: center;
}
table{
margin: 0 auto;
}
p{
font-size: 18 px;
color:#FF0000;
}
</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++)
{
echo "
<tr>
<td><input type='text' name='XH[]'></td>
<td><input type='text' name='XM[]'></td>
<td><input type='text' name='CJ[]'></td>
</tr>";
}?>
<tr>
<td colspan="3">
<input type="submit" name="bt_stu" value="提交">
</td>
</tr>
</table>
</form>
<p align="center">注意:学号值不能重复</p><br/>
<!-- 以上是输入表单 -->
<?php
if(isset($_POST['bt_stu']))
{
foreach($_POST as $Key=>$value)
$$Key=$value;
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></tr>";
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></tr>";
}
echo "</table><br/>";
reset($sum);
while(list($key,$value)=each($sum))
{
list($stu_number,$stu_name,$stu_score)=$value;
if($stu_number=="181101")
{
echo "<p align='center'>";
echo $stu_number."的姓名为:".$stu_name.",";
echo "成绩为:".$stu_score;
break;
}
}
}
?>
正则表达式
<meta charset="UTF-8">
<html>
<head>
<title>注册页面</title>
<style type="text/css">
<!--
.STYLE1{font-size: 14px;color: red;}
-->
div{
text-align: cenetr;
font-size: 24px;
color: #0000FF;
}
table{
margin: 0 auto;
}
</style>
</head>
<body>
<form name="fr1" method="post" action="">
<div align="center">用户注册</div>
<table border="1" width="480">
<tr><td width="80">用户名</td>
<td><input type="text" name="ID">
<td class="STYLE1">*6~12个字符(数字,字母和下划线)
</td>
</tr>
<tr><td>密码:</td>
<td><input type="password" name="PWD"></td>
<td class="STYLE1">*6~20个数字</td>
</tr>
<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 class="STYLE1">*有效的邮件地址
</td>
</tr>
<tr><td colspan="3" align="center">
<input type="submit" name="GO" value="注册">
<input type="reset" name="NO" value="取消">
</td> </tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['ID']))
{
$id=$_POST['ID'];
$pwd=$_POST['PWD'];
$birthday=$_POST['BIRTHDAY'];
$Email=$_POST['EMAIL'];
$checkid=preg_match('/^\w{6,12}$/',$id);
$checkpwd=preg_match('/^\d{6,12}$/',$pwd);
$checkbirthday=preg_match('/^\d{4}-(0?\d|1?[012])-(0?\d|[12]\d|3[01])$/',$birthday);
$checkEmail=preg_match('/^[a-zA-Z0-9_\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/',$Email);
if(!$checkid)
echo "<script>alert('用户名格式错误!')</script>";
elseif(!$checkpwd)
echo "<script>alert('密码格式错误!')</script>";
elseif(!$checkbirthday)
echo "<script>alert('出生日期格式错误!')</script>";
elseif(!$checkEmail)
echo "<script>alert('E-mail格式错误!')</script>";
else
echo "注册成功!";
}
<meta charset="UTF-8">
<?php
echo "请输入学号:<br/>";
echo "<form method='post'>";
for($i=1;$i<5;$i++)
{
echo "<input type='text' name='stu[]' size='6'>";
if($i<4)
echo "-";
}
echo "<input type='submit' name='bt' value='提交'><br/>";
echo "<h4><font color='#ff1493'>使用逗号分隔字符</h4>";
echo "<input type='text' name='tx1' placeholder='输入带中文逗号的语句'>";
echo "<input type='submit' name='sub' value='提交'><br/>";
echo "</form>";
echo "<h3><font color='red'>htmlspecialchars() 函数把预定义的字符转换为 HTML 实体</font></h3>";
$str = "aa & 'bb'";
echo htmlspecialchars($str, ENT_COMPAT); // 只转换双引号
echo "<br>";
echo htmlspecialchars($str, ENT_QUOTES); // 转换双引号和单引号
echo "<br>";
echo htmlspecialchars($str, ENT_NOQUOTES); // 不转换任何引号
if(isset($_POST['bt']))
{
$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,"1811"))
{
$string=str_replace("1811","1810",$value);
$jsj[$k]=$string;
$k++;
}
}
echo "计算机专业的学号如下:<br/>";
echo implode("@",$jsj);
}
if(isset($_POST['sub']))
{
$arr1=$_POST['tx1'];
$arr2=explode(",",$arr1);
$a=$arr2[0];
$b=$arr2[1];
echo "第一段字符串是:".$a."第二段字符串是:".$b;
}