473,507 Members | 3,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

spaces in array_keys($_GET)?

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
2 2652
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3326
by: Phil Powell | last post by:
Hi, I am basing this upon my study of the array_search and array_keys functions in www.php.net and www.zend.com and www.nyphp.org. I have this array, $this->propertyArray, which I have passed...
19
11125
by: Chris Allen | last post by:
Hi I'm new to PHP and I'm trying to create a Login Form. Once the user has logged in then he shouldn't have to log in again. The trouble is I'm getting a new session ID between every page and so...
5
1716
by: michel | last post by:
Here's the snip: <?php // edit records directly ask for authorisation first-->later include "../includes/db_connect.php"; $id=$_GET; $qry="SELECT * FROM eame WHERE id=$id";...
3
6592
by: Armin Irger | last post by:
Hi, i'am running a debian sarge with the delivered apache2 mysql and php4. The file "mitarbeiter_eingabe.php" gets the data over a html <FORM> and send it to...
27
5290
by: meltedown | last post by:
urlencode turns # into %23 When I sent it thru $_GET, it dissapears, along with anything that comes after it. for example: urlencode turns HOYDM_EXC_#4_NAT into HOYDM_EXC_%234_NAT When I...
2
6530
by: David | last post by:
Sent this to alt.php a couple of days back, but doesn't look like I'll get an answer, so trying here. I'm trying to convert a script to use friendly URLs, I've done this before, but my PHP...
4
10714
by: Sen | last post by:
Hi, why: $n = count($_GET); for($i=0; $i<$n; $i++) { echo $_GET }
9
11473
by: Jeff | last post by:
I have a legacy database table that has spaces in the field names. So I have a form that looks like this: <input type="text" name="name with space" value="some_value"> on the server I have:...
1
1507
Ciary
by: Ciary | last post by:
hi all, new day, and already a new problem (i'm really posting to much questions :-O ) like specified in an earlier question, i'm using an access database in my website. to get it i'm using a...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.