?
Solved

How do I split a complex URL string in Coldfusion?

Posted on 2010-09-20
3
Medium Priority
?
1,354 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 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