Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

removing the "%20" from an URL variable

New Here ,
Dec 14, 2010 Dec 14, 2010

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.

1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 14, 2010 Dec 14, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 15, 2010 Dec 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 15, 2010 Dec 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2010 Dec 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#">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 15, 2010 Dec 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2010 Dec 15, 2010
LATEST

Very kind of you, Scott.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources