Copy link to clipboard
Copied
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çais</a></div></li>
Copy link to clipboard
Copied
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.