spaces in array_keys($_GET)?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yawnmoth

    spaces in array_keys($_GET)?

    Say I have the following script - test.php:

    <?
    if (count($_GET) != 0)
    {
    foreach(array_k eys($_GET) as $var)
    {
    echo "$var<br />";
    }
    }
    ?>

    Is it possible for $var to contain a space? If I call "test.php?t his
    is=a test" it gets turned into "test.php?this% 20is=a%20test" by the
    browser and the output of the above is "this_is" - not "this is". If I
    call "test.php?this+ is=a+test", the output is still "this_is".

    I'm gonna guess it isn't possible - I just want to make sure.

  • Kimmo Laine

    #2
    Re: spaces in array_keys($_GE T)?

    "yawnmoth" <terra1024@yaho o.com> kirjoitti
    viestissä:11348 87049.415099.28 1110@f14g2000cw b.googlegroups. com...[color=blue]
    > Say I have the following script - test.php:
    >
    > <?
    > if (count($_GET) != 0)
    > {
    > foreach(array_k eys($_GET) as $var)
    > {
    > echo "$var<br />";
    > }
    > }
    > ?>
    >
    > Is it possible for $var to contain a space? If I call "test.php?t his
    > is=a test" it gets turned into "test.php?this% 20is=a%20test" by the
    > browser and the output of the above is "this_is" - not "this is". If I
    > call "test.php?this+ is=a+test", the output is still "this_is".
    >
    > I'm gonna guess it isn't possible - I just want to make sure.[/color]


    It's mentioned in the php manual that: "A valid variable name starts with a
    letter or underscore, followed by any number of letters, numbers, or
    underscores." - so no, it's not possible, as space is not either number,
    letter nor an underscroe. The reason for this is that a Php Fairy dies every
    time someone uses a space in a variable name. So think about the faries,
    don't use the spaces.

    --
    SETI @ Home - Donate your cpu's idle time to science.
    Further reading at <http://setiweb.ssl.ber keley.edu/>
    Kimmo Laine <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id>


    Comment

    • Jan Pieter Kunst

      #3
      Re: spaces in array_keys($_GE T)?

      In article <do39vc$qdb$1@p hys-news4.kolumbus. fi>, "Kimmo Laine"
      <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id> wrote:
      [color=blue]
      > "yawnmoth" <terra1024@yaho o.com> kirjoitti
      > viestissä:11348 87049.415099.28 1110@f14g2000cw b.googlegroups. com...[color=green]
      > > Say I have the following script - test.php:
      > >
      > > <?
      > > if (count($_GET) != 0)
      > > {
      > > foreach(array_k eys($_GET) as $var)
      > > {
      > > echo "$var<br />";
      > > }
      > > }
      > > ?>
      > >
      > > Is it possible for $var to contain a space? If I call "test.php?t his
      > > is=a test" it gets turned into "test.php?this% 20is=a%20test" by the
      > > browser and the output of the above is "this_is" - not "this is". If I
      > > call "test.php?this+ is=a+test", the output is still "this_is".
      > >
      > > I'm gonna guess it isn't possible - I just want to make sure.[/color]
      >
      >
      > It's mentioned in the php manual that: "A valid variable name starts with a
      > letter or underscore, followed by any number of letters, numbers, or
      > underscores." - so no, it's not possible, as space is not either number,
      > letter nor an underscroe.[/color]

      But the question is not about variable names, but about the content of
      variables. And array keys can certainly contain spaces. It's the
      automatic urlencoding by the browser that messes things up here. Try
      playing around with urldecode(), for instance:

      echo urldecode($var) . '<br />';

      (untested).

      JP

      Comment

      Working...