By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

spaces in array_keys($_GET)?

P: n/a
Say I have the following script - test.php:

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

Is it possible for $var to contain a space? If I call "test.php?this
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.

Dec 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"yawnmoth" <te*******@yahoo.com> kirjoitti
viestissä:11**********************@f14g2000cwb.goo glegroups.com...
Say I have the following script - test.php:

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

Is it possible for $var to contain a space? If I call "test.php?this
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.

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.berkeley.edu/>
Kimmo Laine <an*******************@gmail.com.NOSPAM.invalid>
Dec 18 '05 #2

P: n/a
In article <do**********@phys-news4.kolumbus.fi>, "Kimmo Laine"
<an*******************@gmail.com.NOSPAM.invalid> wrote:
"yawnmoth" <te*******@yahoo.com> kirjoitti
viestissä:11**********************@f14g2000cwb.goo glegroups.com...
Say I have the following script - test.php:

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

Is it possible for $var to contain a space? If I call "test.php?this
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.

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.


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
Dec 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.