<?php
// 定义变量并默认设置为空值
$name = $email = $gender = $comment = $website = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
  $name = test_input($_POST["name"]);
  $email = test_input($_POST["email"]);
  $website = test_input($_POST["website"]);
  $comment = test_input($_POST["comment"]);
  $gender = test_input($_POST["gender"]);
}
function test_input($data)
{
// trim() 函数去除用户输入数据中不必要的字符 (如:空格,tab,换行)。 
$data = trim($data);
//stripslashes()函数去除用户输入数据中的反斜杠 (\)  
$data = stripslashes($data);
/*htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体。
预定义的字符是:
& (和号) 成为 &amp;
" (双引号) 成为 &quot;
' (单引号) 成为 &#039;
< (小于) 成为 &lt;
> (大于) 成为 &gt;
*/
  $data = htmlspecialchars($data);
  return $data;
}
?>

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注