PHP trim and addslashes to multiple input variables
Posted on 2007-04-09
Is there a simple way of trimming and adding slashes to multiple, incoming $_POST or $_GET variables in PHP?
I have several input variables coming in (i.e. $_POST['first'],$_POST['last']) and I'd like to loop through them all, trim any newlines or spaces on either end, and add slashes for MySQL all at once, instead of:
$first = addslashes($_POST['first']);
$last = addslashes($_POST['last']);
$first = trim($first);
$last = trim($last);
I don't want to use magic_quotes because I need more control over where and when the form variable characters are escaped.