Page 1 of 1

[SOLVED] $_POST replacing dots with underscores

Posted: Tue May 15, 2007 4:48 am
by impulse()
I came across a strange problem today. I'm generating hundreds of checkboxes, few of which contain a dot or space in their name. But when these are posted to PHP the dots and spaces are replaced with underscores. This is causing big headaches and I can't see any way around this without stopping PHP replacing those dots and spaces.

Can anybody advise me on what to do with the code from here?

Posted: Tue May 15, 2007 5:26 am
by impulse()
I've found a way around this now, it's a bit of a hack but it works at least.

The code will replace any dots or spaces with "|dot|" or "|space|", or whatever you choose to replace them with.

Code: Select all

$test = array ("alpha", "b.eta", "gam ma");

echo "<form method = 'post'>";

foreach($test as $a) {

  if (strpos($a, ".")) {
    $a = str_replace(".", "|dot|", $a);
    echo "<input type = 'checkbox' name = '$a'> $a";
  }

  elseif (strpos($a, " ")) {
    $a = str_replace(" ", "|space|", $a);
    echo "<input type = 'checkbox' name = '$a'> $a";
  }

  else
    echo "<input type = 'checkbox' name = '$a'> $a";

}

echo "<input type = 'submit' value = 'Test Me'>
      </form>";

print_r($_POST);