Reply to comment

variable variables in PHP5, - or - Dolla Dolla Bills Y'all

Now here's a neat way to get your values out of $_POST, using PHP variable variables (as indicated by the double dollar signs):

foreach($_POST as $key => $value) {
$$key = $value;
}

And now you have all of your post values neatly stowed away in local variables :D The double dollar signs take the value of a pre-existing variable and use that value as the name of a new variable. I'm sure it has other uses but this was the most obvious and most applicable to my line of work.

Note: in the code above you should do a regex match on the values to sanitize the data, particularly to avoid header injection.

Reply

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options