[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I split a complex URL string in Coldfusion?

Posted on 2010-09-20
3
Medium Priority
?
1,386 Views
Last Modified: 2012-06-27
Hello,

I have a URL string with multiple query parameters.  What I would like to do is use a <cfscript function to split the string based on each variable and then build an array with it that will be returned.

In other words, say I have the following URL string:

www.example.com/test.cfm?test1=foo&test2=foo2&test3=foo3

What I woudl like to do is pass that string into a function and then output the variables in an array.

Example of outputted array: ( I know this is not what it looks like when you dump it, but I'm sure you know what I mean.)

test1 | foo
test2 | foo2
test3 | foo3

Thank you very much in advance!!!!
0
Comment
Question by:stracqan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
danrosenthal earned 2000 total points
ID: 33721561
Should be something like this...
<CFSET qs = "www.example.com/test.cfm?test1=foo&test2=foo2&test3=foo3">
<CFSET qsparams = LISTLAST(qs,"?")>

<CFSET myarray = arraynew(2)>
<CFLOOP FROM="1" TO="#listlen(qsparams,"&")#" index="i">
   <CFSET thisparam = LISTGETAT(qsparams,i,"&")>
   <CFSET myarray[i][1] = LISTFIRST(thisparam,"=")>
   <CFSET myarray[i][2] = LISTLAST(thisparam,"=")>
</CFLOOP>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 33721595
(no points ...)

>> LISTFIRST(thisparam,"=")

Just watch out for empty values.  CF list functions tend to ignore those.  If you think you might have empty values like:  something=(empty value)

     www.example.com/test.cfm?test1=foo&something=

Then you might want to use ListToArray(string, delim, preserveEmptyElements)  instead.
0
 

Author Closing Comment

by:stracqan
ID: 33721612
Worked Perfectly!!! Thanks!!!!!!!!!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question