有时,当用户将数据复制并粘贴到输入表单中时,我们会得到如下字符:
没有,“用于开头引号和“用于结尾引号等...
我使用此例程来清理 Web 表单上的大多数输入(我前段时间写过,但也在寻找改进):
function fnSanitizePost($data) //escapes,strips and trims all members of the post array
{
if(is_array($data))
{
$areturn = array();
foreach($data as $skey=>$svalue)
{
$areturn[$skey] = fnSanitizePost($svalue);
}
return $areturn;
}
else
{
if(!is_numeric($data))
{
//with magic quotes on, the input gets escaped twice, which means that we have to strip those slashes. leaving data in your database with slashes in them, is a bad idea
if(get_magic_quotes_gpc()) //gets current configuration setting of magic quotes
{
$data = stripslahes($data);
}
$data = pg_escape_string($data); //escapes a string for insertion into the database
$data = strip_tags($data); //strips HTML and PHP tags from a string
}
$data = trim($data); //trims whitespace from beginning and end of a string
return $data;
}
}
我真的很想避免上面提到的字符被存储在数据库中,我是否需要在我的清理程序中添加一些正则表达式替换?
谢谢,
-
尼古拉斯