Jump to content

[SOLVED] How to parse all post variables


rcorlew

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.