我正在尝试从多个用户输入中删除html标签。我单独尝试了它,但是当我将它变成一个函数时,它<< [not删除了html标签...
$test = array('name' => '<script>alert("HELLO..");</script>',
'phone' => '23497999000000'
);
(clean($test));
function clean($field)
{
foreach ($field as $key => $value) {
$value = htmlspecialchars(strip_tags($value));
}
return $field;
}
function clean($field)
{
foreach ($field as $key => $value) {
$field[$key] = htmlspecialchars(strip_tags($value));
}
return $field;
}
您还想在返回时保留清理后的版本:$test = clean($test);
function clean($field)
{
foreach ($field as $key => $value) {
$field[$key] = htmlspecialchars(strip_tags($value));
}
return $field;
}
$value
的选项通过引用:
function clean($field)
{
foreach ($field as &$value) {
$value = htmlspecialchars(strip_tags($value));
}
return $field;
}