Solved

Parsing URL

Posted on 2008-06-24
5
218 Views
Last Modified: 2013-12-24
I have a URL with variables that i need to parse,
http://server.com/ind3.cfm?CNO=12345&sn1=alastl&sn2=bsecond&sn3=cthird

I have the following loop to strip out the sn's,

<cfset SNs = "">
<cfloop index="i" from="1" to="3">
      <cfif IsDefined("url.sn"&i)>
            <cfset intSN = Evaluate("url.sn"&i)>
            <cfif intSN NEQ "">
                  <cfquery name="GetCSN" datasource="#request.dataSource#">
                        select * from CReg where ID = #intID#
                  </cfquery>
                  <cfloop query="GetChildSN">
                        <cfset SNs = ListAppend(SNs, intSN)>
                  </cfloop>
            </cfif>
      </cfif>
</cfloop>

I looked at using the left, right and mid functions but I wanted to see if there is a better way to strip the names (sn#) from the variables. For example sn1=alast, this should be firstname1 =a and lastname1 =last

0
Comment
Question by:usky1
  • 2
  • 2
5 Comments
 
LVL 2

Assisted Solution

by:adobe116
adobe116 earned 75 total points
ID: 21862514
I'm not sure I should be responding because I don't have the exact answer, but I know where you can find it. I have Ben Forta's "Teach yourself Regular Expressions" It's a tiny book and costs hardly anything... It's a real easy read and I usually read it in one sitting.  Problem is that I never use regular expressions and over a period of a few months it seeps right out of my overloaded brain.

If I found it I could probably find what you needed and I recommend it highly...

Essentially, I think you want to replace 'everything up to '&sn1=' with a blank string, and then you want to find each instance of "&snNUMBER=CharactersUpTo(&orEOL) and replace the &SN#= with a comma.

That would create your list.

The documentation for RegEx in CF is on http://livedocs.adobe.com/coldfusion/8/htmldocs/regexp_01.html

and I'm sure if I dig around I could find a url stripper function that does this... but it's where you would start.  Sorry I can't help more.  But if you find yourself doing this often, invest in that book... I'm going to look for it now actually because it really annoys me that I don't know the answer to your question.  Best of luck though


0
 

Author Comment

by:usky1
ID: 21865336
Thanks for the book suggestion and link. I will look into both of those to see if I can figure this out. I'm going to leave this open so hopefully I will get some additional help.
0
 
LVL 28

Accepted Solution

by:
Pravin Asar earned 425 total points
ID: 21875166
One of way to process the querystring and convert to array

Try the following snippet

<cfset myarray=ListToArray(#CGI.QUERY_STRING#, "&")>

<cfdump var="#myarray#" expand="yes">

<cfloop index="ax" from="1" to="#ArrayLen(myarray)#">
      <cfoutput>#myarray[ax]#</cfoutput>
    <cfset variable=#ListToArray(#myarray[ax]#,"=")#>
    <cfdump var="#variable#" expand="yes">
</cfloop>

0
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 21876464
Here is another apporach, which processes query_string and build a CF Query Structure.


<cfscript>
   myquery = QueryNew("name,value");
   myarray=ListToArray("#CGI.QUERY_STRING#", "&");
   for (ax=1; ax LTE ArrayLen(myarray); ax=ax+1) {
         myvar=ListToArray(myarray[ax],'=');
               QueryAddRow(myquery);
               QuerySetCell(myquery, "name", myvar[1], ax);  
            if (ArrayLen(myvar) GT 1) {
               QuerySetCell(myquery, "value", myvar[2], ax);
            }
            else {
               QuerySetCell(myquery, "value", "", ax);
            }
            }
</cfscript>
<cfdump var="#myquery#" expand="yes">
0
 

Author Closing Comment

by:usky1
ID: 31470312
pravinasar: That worked great. thanks for your help.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
OpenLDAP set password to expire 7 542
Reverse Proxy Server 6 78
PHP in Apache server 20 89
question about access to website 2 68
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

864 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now