案例:PHP案例     状态:不可编辑再运行    进入竖版
 运行结果 
x
 
1
2
<!DOCTYPE HTML> 
3
<html>
4
<head>
5
</head>
6
<body> 
7
8
<?php
9
// define variables and set to empty values
10
$name = $email = $gender = $comment = $website = "";
11
12
if ($_SERVER["REQUEST_METHOD"] == "POST") {
13
   $name = test_input($_POST["name"]);
14
   $email = test_input($_POST["email"]);
15
   $website = test_input($_POST["website"]);
16
   $comment = test_input($_POST["comment"]);
17
   $gender = test_input($_POST["gender"]);
18
}
19
20
function test_input($data) {
21
   $data = trim($data);
22
   $data = stripslashes($data);
23
   $data = htmlspecialchars($data);
24
   return $data;
25
}
26
?>
27
28
<h2>PHP 验证实例</h2>
29
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
30
   姓名:<input type="text" name="name">
31
   <br><br>
32
   电邮:<input type="text" name="email">
33
   <br><br>
34
   网址:<input type="text" name="website">
35
   <br><br>
36
   评论:<textarea name="comment" rows="5" cols="40"></textarea>
37
   <br><br>
38
   性别:
39
   <input type="radio" name="gender" value="female">女性
40
   <input type="radio" name="gender" value="male">男性
41
   <br><br>
42
   <input type="submit" name="submit" value="提交"> 
43
</form>
44
45
<?php
46
echo "<h2>您的输入:</h2>";
47
echo $name;
48
echo "<br>";