1
输入端
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="controller.php" method="get">
名字: <input type="text" name="name">
年龄: <input type="text" name="age">
邮箱: <input type="text" name="email">
<input type="submit" value="提交">
</form>
</body>
</html>
验证端:
<?php
// 定义个字段规则
$filters = array (
"name" => array (
"filter" => FILTER_SANITIZE_STRING
),
"age" => array (
"filter" => FILTER_VALIDATE_INT,
"options" => array (
"min_range" => 1,
"max_range" => 120
)
),
"email" => FILTER_VALIDATE_EMAIL
);
$result = filter_input_array ( INPUT_GET, $filters );
// 结果判断
if (! $result ["name"]) {
echo "姓名输入错误";
} else if (! $result ["email"]) {
echo "邮箱输入错误";
} else if (! $result ["age"]) {
echo "年龄输入错误";
} else {
echo "输入错误";
}
?>
部分摘自菜鸟教程。
未完待续。。。