PHP converts form field characters to underscores
- From: james.gauth@xxxxxxxxxxxxxx
- Date: Wed, 13 Feb 2008 02:45:16 -0800 (PST)
I'm currently writing a system which contains relatively arbitrary
form field names (the field names are re-used as headings in a
subsequent form-to-mail kind of script). I've noticed that PHP
converts certain form field-name characters to underscores.
After doing some searching for related bugs, these are the only
bugs.php.net entries I could find:
http://bugs.php.net/bug.php?id=34578
http://bugs.php.net/bug.php?id=42677
http://bugs.php.net/bug.php?id=17574
The first two responses cite the "because of register globals, any
form field which does not contain valid variable-name characters is
converted" whereas the last one points out where this really
contradicts itself, PHP accepts form field names with all manner of
non-printable characters _including_ form field names which start with
numbers. The following code writes a form to test which characters are
acceptable to PHP:
---------------------------
<html>
<head><title>test</title></head>
<body>
<form method="post">
<?php
for ($i=1; $i<255; $i++) {
print "<input type=\"hidden\" name=\"&#$i;\" />\n";
}
?>
<input type="Submit" />
</form>
<?php
if (count($_POST)) {
for ($i=1; $i<255; $i++) {
if (!isset($_POST[chr($i)])) {
print $i.' ('.dechex($i).')(&#'.$i.';) doesnt exist<br />';
}
}
}
?>
</body>
</html>
---------------------------
The sticking point for me is that space characters (%20) as well as
dot characters (%2E) are converted to underscores, yet all other ASCII
characters (with the exception of square brackets which at least have
some explainable meaning) are left as-is. I lose data because I can't
tell which fields had spaces, dots or underscores in them originally.
The only solution I can think of is replacing dots or spaces with non-
printable characters and then converting them back when I parse the
$_REQUEST array.
Can anyone shed light on why normal (and very useful) characters are
converted whereas others are left alone?
.
- Follow-Ups:
- Re: PHP converts form field characters to underscores
- From: Jerry Stuckle
- Re: PHP converts form field characters to underscores
- Prev by Date: Free Web Hosting for PHP
- Next by Date: least squares algorithm
- Previous by thread: Free Web Hosting for PHP
- Next by thread: Re: PHP converts form field characters to underscores
- Index(es):
Relevant Pages
|