472,993 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

function to extract key/value pairs?

I've searched and searched for a function to create an array from a
string maintaining key/value pairs and keep coming up blank. This
seems to me that it would be quite commonly used.

What I am doing is trying to pass an array using $_GET. To pass the
array, it is rather simple to add it to my get string breaking the
array into key,value,key,value,key,value. The problem is reading it
back into an array. I've tried explode but that places each key and
value as a value in an array. I've tried split and think it might work
except it chokes if there is only one key/value. Is there a function
to do what I want or is there a better way to pass an array?

--
Stan McCann, RETIRED!!, "Uncle Pirate" http://stanmccann.us/
Implementing negative score for googlegroup postings, see
http://blinkynet.net/comp/uip5.html
A zest for living must include a willingness to die. - R.A. Heinlein
Oct 25 '06 #1
3 2786

Stan McCann wrote:
I've searched and searched for a function to create an array from a
string maintaining key/value pairs and keep coming up blank. This
seems to me that it would be quite commonly used.

What I am doing is trying to pass an array using $_GET. To pass the
array, it is rather simple to add it to my get string breaking the
array into key,value,key,value,key,value. The problem is reading it
back into an array. I've tried explode but that places each key and
value as a value in an array. I've tried split and think it might work
except it chokes if there is only one key/value. Is there a function
to do what I want or is there a better way to pass an array?

--
Yes there is a better way to pass an array. Just pass an array :)

page.php?foo[0]=bar&foo[1]=baz&foo[2]=bah

Then $_GET['foo'] will be an array.

Oct 25 '06 #2
Hi Stan --

Perhaps you could use a combination of serialize and base64_encode to
solve your problem. The only catch is that encoding strings in base64
can result in a really long URL and may (ultimately) exceed some
browsers' limits. But if the array you are working with is relatively
small, this solution may be feasible.

First serialize your array, then encode it in base64. Send the encoded
string as your GET variable. On the other side, decode the GET
variable, then unserialize it. This should reassemble your array
correctly.

Geoffrey
Stan McCann wrote:
I've searched and searched for a function to create an array from a
string maintaining key/value pairs and keep coming up blank. This
seems to me that it would be quite commonly used.

What I am doing is trying to pass an array using $_GET. To pass the
array, it is rather simple to add it to my get string breaking the
array into key,value,key,value,key,value. The problem is reading it
back into an array. I've tried explode but that places each key and
value as a value in an array. I've tried split and think it might work
except it chokes if there is only one key/value. Is there a function
to do what I want or is there a better way to pass an array?

--
Stan McCann, RETIRED!!, "Uncle Pirate" http://stanmccann.us/
Implementing negative score for googlegroup postings, see
http://blinkynet.net/comp/uip5.html
A zest for living must include a willingness to die. - R.A. Heinlein
Oct 26 '06 #3
"Geoffrey" <go***********@yahoo.comwrote in
news:11**********************@b28g2000cwb.googlegr oups.com:
Hi Stan --

Perhaps you could use a combination of serialize and base64_encode
to solve your problem. The only catch is that encoding strings in
base64 can result in a really long URL and may (ultimately) exceed
some browsers' limits. But if the array you are working with is
relatively small, this solution may be feasible.

First serialize your array, then encode it in base64. Send the
encoded string as your GET variable. On the other side, decode the
GET variable, then unserialize it. This should reassemble your
array correctly.
That seems to do the trick. Thanks a bunch.

--
Stan McCann, RETIRED!!, "Uncle Pirate" http://stanmccann.us/
Implementing negative score for googlegroup postings, see
http://blinkynet.net/comp/uip5.html
A zest for living must include a willingness to die. - R.A. Heinlein
Oct 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ken Fine | last post by:
I have a menu system that has nodes that can be opened or closed. In an effort to make my code more manageable, I programmed a little widget tonight that keeps track of the open/active item and...
6
by: Csaba Gabor | last post by:
I'd like to be able to pass a key1/value1 pair into a function and have that function have a local variable by the name of key1 to which value1 is assigned. for example, I'd like to call...
44
by: RB | last post by:
How to extract bytes from long, starting from the last byte? For example, I have a long number: 0x12345678 I need to represent it as the following bytes list: 0x78, 0x56, 0x34, 0x12 Thanks in...
3
by: Jeff L. | last post by:
I have an interesting problem and I'm not coming up with any answers in my searches, so hopefully someone can give me a hand with this. I have a feeling it's easy, but I usually get my nose stuck...
7
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
25
by: hifrnds007 | last post by:
how the function poiners avoids the usage of switch cases?
1
by: Edwin.Madari | last post by:
from each line separate out url and request parts. split the request into key-value pairs, use urllib to unquote key-value pairs......as show below... import urllib line = "GET...
19
by: JRough | last post by:
I have used this function to create a string called $headers: function GetHeaders($file_name){ return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th> <th><a href='"....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.