Skip to main content
Known Participant
September 15, 2010
Question

'&' and '?' in a URL

  • September 15, 2010
  • 1 reply
  • 496 views

How to use '&' and '?' in a URL?

May I do

<cfset str = str & "&lang=fr">

and

<cfset path = "http://" & servername & "/" & path & "?" & str>

as in the following code:

<cfset servername = #cgi.SERVER_NAME#>

<cfset script = #cgi.SCRIPT_NAME#>

<cfset str = #cgi.query_string#>

<cfif find("lang=en", str)>

      <cfset str = ReplaceNoCase(str, "lang=en", "lang=fr")>

<cfelse>

     <cfset str = str & "&lang=fr">

</cfif>

<cfset position = find("TEST", script)>

<cfset length = Len(script)>

<cfset path = Mid(script, position, length)>

<cfset path = "http://" & servername & "/" & path & "?" & str>

<li><div><a href="<cfoutput>#path#</cfoutput>">Fran&ccedil;ais</a></div></li>

This topic has been closed for replies.

1 reply

Inspiring
September 16, 2010

You appear to already know how to use ampersands and question marks in a url.  For the rest of it, if you are not achieving the desired result, look at your variables.  In other words, output early and output often.  Once what you see is different than what you expect, you'll know what to fix.