Solved

How do I split a complex URL string in Coldfusion?

Posted on 2010-09-20
3
1,325 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 500 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

688 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