rcorlew Posted April 1, 2007 Share Posted April 1, 2007 I know how to parse posted variables to do preg_match and string functions. What I am wondering is if there is a way to parse global variables as a function. I am not too famialiar with functions per say, but I need to learn how to master them in order to finish my project. Here is a sample code that I am using: <?php $name = $_POST["name"]; $favorite = $_POST["favorite"]; $time = $_POST["time"]; echo "Your name is $name and your favorite food is $favorite, you like to eat this at $time"; ?> What I am trying to do is striptags and preg_match the data to cleanse it. I know how to do that on a variable by variable basis, but I have a total of 31 variables that are user inputed. I hear that php5 has a cleanse function built in, but this is on php4. I am not asking someone to write my whole project just show me how to parse gloabal $_POST variables. Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/45107-solved-how-to-parse-all-post-variables/ Share on other sites More sharing options...
kenrbnsn Posted April 1, 2007 Share Posted April 1, 2007 You can loop though the $_POST array with a foreach loop: <?php $cleaned = array(); foreach($_POST as $key => $value) $cleaned[$key] = trim(stripslashes($value)); // or whatever you do to cleanse your variables ?> Ken Link to comment https://forums.phpfreaks.com/topic/45107-solved-how-to-parse-all-post-variables/#findComment-218964 Share on other sites More sharing options...
rcorlew Posted April 1, 2007 Author Share Posted April 1, 2007 Thank you very much!! Link to comment https://forums.phpfreaks.com/topic/45107-solved-how-to-parse-all-post-variables/#findComment-218967 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.