matlyn Posted February 24, 2007 Share Posted February 24, 2007 I am currently passing data from a form to a .php script for processing. First item is to clean user input with statements like: $cleanFname = trim($_POST[fname]); $cleanFname = strip_tags($cleanFname); $cleanLname = trim($_POST[lname]); $cleanLname = strip_tags($cleanLname); etc... times however many variables are in the form. A few varables are ok but for a form with many variables this could get to be a long list. Can this process be done combining foreach() with the $_POST array so that I can cover all passed variables with just a couple of lines of code vs a long repetitive list? Thanks Link to comment https://forums.phpfreaks.com/topic/39953-solved-clean-user-input-using-foreach/ Share on other sites More sharing options...
emehrkay Posted February 24, 2007 Share Posted February 24, 2007 i would assume this would work foreach($_POST as $key => $val){ $$key = trim($val); } instead of having "clean" prefix the var name, they will just be named whatever they are in the post Link to comment https://forums.phpfreaks.com/topic/39953-solved-clean-user-input-using-foreach/#findComment-193269 Share on other sites More sharing options...
matlyn Posted February 25, 2007 Author Share Posted February 25, 2007 Sweeeet. Thanks emehrkay! Link to comment https://forums.phpfreaks.com/topic/39953-solved-clean-user-input-using-foreach/#findComment-193631 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.