I have $_GET['tags'] = "apples, oranges, bananas, grapes, cherries"
I need to place the data into an array ($tags).
What is a quick way to trim each item and perform security functions (stripping html, special chars)?
With array_walk() you could write your tag cleaning function separately, and then easily apply it to your incoming data.
function sterilize(&$val,$key)
{
//do whatever security you need here
$val = trim($val);
$val = strip_tags($val);
//etc
return htmlspecialchars($val);
}
$bad_values = explode(',',$_GET['tags']);
array_walk($bad_values,'sterilize');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With