473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 2808

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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.