Hi:

I have a form which has bunch of fields. Some of those fields have dots in their names. For example: name="state.admin"

I process all the submitted values in an array, however the dot gets replaced with an under score, like state_admin

I use the following code to display all the fields on the screen.:

foreach ($_GET as $key => $value)
		{ echo $key."===".$value."<br>"; }

That's when I noticed the underscore.
The filed name must stay with the dot.
Any ideas as a work around?

thanx

Kamy

    Why must it be kept as a dot?

    If your application honestly requires that the key names contain the periods, then I can see two options:

    1. If you don't use underscores in your array keys (or any other special character that is converted to an underscore), you could comb through the $POST array and change all underscores to periods in the array keys.

    2. Manually populate the $_POST array yourself:

      $temp = explode('&', file_get_contents('php://input'));
      $_POST = array();
      foreach($temp as $param) {
      	$param = explode('=', $param);
      	$_POST[$param[0]] = urldecode($param[1]);
      }

      And there is, of course, another work-around: change the form field names to not include "." characters. 😉

      FYI, we can all thank the ever-unpopular register_globals for this, as it would appear to be the reason that the conversion of dots to underscores ever was implemented. Since you can't have a scalar variable named $foo.bar, they did the conversion in order that it would be $foo_bar when using register_globals (which none of us does any more, right?).

        Isn't it also that . is used to concatenate strings?

        so $foo.bar would be $foo + the constant bar.
        After that sentence I got very thirsty. 😃

          HalfaBee wrote:

          Isn't it also that . is used to concatenate strings?

          so $foo.bar would be $foo + the constant bar.
          After that sentence I got very thirsty. 😃

          Yes, that is the underlying cause for my statement: "Since you can't have a scalar variable named $foo.bar . . ." However, if that had never been an issue, then the replacement would never have been required, since $array['foo.bar'] is fine, though it could be a problem since PHP would let you get away with $array[foo.bar] with just a couple "undefined constant" notices. :rolleyes:

            Dots in array keys also stops the extract() function from working properly.

              As well as [man]parse_str/man, even if you choose to use the second parameter (thought I'd get away with using that function, but alas, it converted the periods to underscores as well).

                I have no control over the field names.
                It was decided by the engineer team, before I got on board.

                When I pass the vars through Get, in the location bar they appear correctly. However echoing them through PHP is troublesome.

                  I mark this resolved.
                  I found another workaround , based on variable name.

                  thank you

                    Write a Reply...