本例简单对邮箱地址进行判断,将输入框中的字符“我”替换为字符“本人”
<meta http-equiv="Content-type" Content="text/html;charset=UTF-8;" />
<!DOCTYPE html>
<style type="text/css">
p{font-family:"方正舒体";font-size:18px;}
div{font-family:"黑体";font-size:18px}
</style>
<form name="f1" method="post" action="">
<p>你的Email地址:<br><input type="email" name="Email" size=31><br>
你的留言: <br><textarea name="note" rows=10 cols=30></textarea>
<br><input type="submit" name="bt1" value="提交"><input type="reset" name="bt2" value="清空">
</p>
</form>
<?php
if(isset($_POST['bt1']))
{
$Email=$_POST['Email'];
$note=$_POST['note'];
if(!$Email||!$note)
echo"<script>alert('Email地址和留言请填写完整!')</script>";
else
{
$array=explode("@",$Email);
if(count($array)!=2)
echo"<script>alert('Email地址格式错误!')</script>";
else
{
$username=$array[0];
$netname=$array[1];
if(strstr($username,".") or strstr($username,","))
echo"<script>alert('Email地址格式错误!')</script>";
else
{
$str1=htmlspecialchars("<");
$str2=htmlspecialchars(">");
$newnote1=str_replace("我","本人",$note);
$newnote2=htmlspecialchars($newnote1);
echo"<div>";
echo"用户".$str1.$username.$str2."你好! ";
echo"你是".$netname."网友!<br>";
echo"<br>你的留言是:<br> ".$newnote2."<br>";
echo"</div>";
}
}
}
}
?>