Skip to main content
New Participant
December 15, 2010
Question

removing the "%20" from an URL variable

  • December 15, 2010
  • 2 replies
  • 1906 views

I am receiving a returned URL that looks something like this:

http://myDomanin.com//gateway.cfm?custom%20first_nam=slam&custom%20last_nam=mally

The problem is that I need to get the first_nam variable to be "slam" and the last_nam variable to be "mally" (using the example above).

Unfortunately, I am presented with the URL structure that gives me custom%20first_nam=slam and custom%20last_nam=mally. 

How would I work some CF magic so that I could strip the URL of the "custom%20" ?

Many thanks in advance for you help with this.

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    December 15, 2010

    scottb50@gmail.com wrote:

    removing the "%20" from an URL variable

    In general, you shouldn't bother about the url. This is because the url is someone else's. You are therefore not in a position to do anything about it.


    In ancient Egypt, there were lots of complaints about the sand in bread. Bread was the staple diet. Sand in bread meant worn teeth, and exposed tooth nerves. It probably accounted for the most pain in Egyptian life (French pun intended!). There was little to nothing the consumer could do, except pick out the sand grains(which would take forever), or bake his own.


    The url you mention was baked by someone else. You therefore have to take it as-is. It's up to you to pick out the sand grains.


    Bread remains nutritious with or without sand grains. Right or wrong, the url you mention still contains the following information


    custom first_nam=slam

    custom last_nam=mally


    You could, for example, get the information from the url struct, as follows:


    <cfset fname = url["custom first_nam"]>
    <cfset lname = url["custom last_nam"]>


    Alternatively, you could get the data by means of CGI, as follows:

    <cfset myVar = arrayNew(1)>
    <cfset n = 1>


    <cfloop list="#CGI.QUERY_STRING#" delimiters="&" index="query_string_element">
          <cfset myVar = listGetAt(query_string_element,2,"=")>
        <cfset n=n+1>
    </cfloop>


    <cfdump var="#myvar#">

    scottb50Author
    New Participant
    December 15, 2010

    OK, BKBK, this is the single greatest response to a forum question I have

    ever received. Not only did it solve my problem elegantly, but I loved the

    parable. This literally lets me have my bread and eat it too!

    -- Scott

    BKBK
    Community Expert
    December 15, 2010

    Very kind of you, Scott.

    ilssac
    Inspiring
    December 15, 2010

    You could do either a replace() or rereplace() to covert that string to an empty string.

    But I would probaly just urlDecode() the query string.  Since %20 is simple the url encoding of a space character.

    Inspiring
    December 15, 2010

    Or one could approach this from the perspective of "garbage in, garbage out".  If the URL is malformed, then it should be rejected: 404 it to

    "encourage" the visitors to hit the file with the correct URL.  Or at the very least 301 it to the correct URL.

    I would not actually "fix" this sort of thing with code.  I'd fix it at the source of the problem.

    --

    Adam

    scottb50Author
    New Participant
    December 15, 2010

    Thanks for the response, Adam! I would love to be able to fix it at the

    source, but I don't have any control over the source. It is coming from

    AWeber.

    -- Scott