I'm trying to remove html tags from multiple user input. I tried it individually it worked, but when i turned it into a function it's not removing the html tags...
$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;
}
You're set the value of $value, but lose it, when it comes out of scope.
I think it'll be correct:
function clean($field)
{
foreach ($field as $key => $value) {
$field[$key] = htmlspecialchars(strip_tags($value));
}
return $field;
}