Created
April 30, 2014 18:53
-
-
Save boughtonp/dcd50e8e654c705df6c8 to your computer and use it in GitHub Desktop.
QueryStringToStruct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffunction name="QueryStringToStruct" returntype="struct" output=false access="public" | |
hint="Converts a querystring into a struct of name value pairs." | |
> | |
<cfargument name="QS" type="string" required=true /> | |
<cfargument name="Decode" type="Boolean" default=true /> | |
<cfargument name="Delimiter" type="String" default="," | |
hint="Used to delimit values provided from multiple keys of same name." | |
/> | |
<cfset var Results = StructNew() /> | |
<cfloop index="local.CurItem" list=#Arguments.QS# delimiters="&" > | |
<cfif Arguments.Decode> | |
<cfset var Key = UrlDecode(ListFirst(CurItem,"=")) /> | |
<cfset var Value = UrlDecode(ListRest(CurItem,"=")) /> | |
<cfelse> | |
<cfset var Key = ListFirst(CurItem,"=") /> | |
<cfset var Value = ListRest(CurItem,"=") /> | |
</cfif> | |
<cfif StructKeyExists( Results , Key )> | |
<cfset Results[Key] &= Arguments.Delimiter & Value /> | |
<cfelse> | |
<cfset Results[Key] = Value /> | |
</cfif> | |
</cfloop> | |
<cfreturn Results /> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment