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?
[SOLVED] $_POST replacing dots with underscores
Moderator: General Moderators
-
impulse()
- Forum Regular
- Posts: 748
- Joined: Wed Aug 09, 2006 8:36 am
- Location: Staffordshire, UK
- Contact:
[SOLVED] $_POST replacing dots with underscores
Last edited by impulse() on Tue May 22, 2007 8:14 am, edited 1 time in total.
-
impulse()
- Forum Regular
- Posts: 748
- Joined: Wed Aug 09, 2006 8:36 am
- Location: Staffordshire, UK
- Contact:
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.
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);