473,804 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

spaces in array_keys($_GE T)?

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.

Dec 18 '05 #1
2 2666
"yawnmoth" <te*******@yaho o.com> kirjoitti
viestissä:11*** *************** ****@f14g2000cw b.googlegroups. com...
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.

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 <an************ *******@gmail.c om.NOSPAM.inval id>
Dec 18 '05 #2
In article <do**********@p hys-news4.kolumbus. fi>, "Kimmo Laine"
<an************ *******@gmail.c om.NOSPAM.inval id> wrote:
"yawnmoth" <te*******@yaho o.com> kirjoitti
viestissä:11*** *************** ****@f14g2000cw b.googlegroups. com...
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.

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
3350
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 into a class as a mocked-up version of the same formatting as _GET and _POST arrays inasmuch as the keys are variable names and vals are the variable values. Here is the print_r printout of $this->propertyArray for example: Array (
19
11153
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 it doesn't recognise the user. I've used Session_Start() which I thought was meant to maintain the session variables between pages but it doesn't do work. Any ideas or FAQ's?
5
1733
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"; $res=mysql_query($qry); if(!$res)die("something not right");
3
6615
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 "mysql_mitarbeiter_daten_hinzufuegen.php" to write it in an mysql database. These already worked on php3 and mysql-3 and now on php4 and mysql4 it doesn't work. I can't found any changes between php3 and php4, mysql3 and mysql4 that explained the fact that only empty spaces are...
27
5338
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 use it in an url
2
6548
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 skills are quite basic so far, far from proficient at this. ..htaccess file- DirectoryIndex default.php index.asp index.html index.htm index.php
4
10734
by: Sen | last post by:
Hi, why: $n = count($_GET); for($i=0; $i<$n; $i++) { echo $_GET }
9
11506
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: $field_name = 'name with space';
1
1522
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 DOM-object in php (see code below). this works fine as long as the database doesn't contain tables with spaces in their names. my problem is that my users should be able to select any access database. not only those without spaces. $db = $_GET; ...
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10090
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6863
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.