Utility Function: JSClean()
- October 29, 2008 5:30 AM
- ColdFusion, Utility Function
- Comments (0)
This one I use a lot when writing out JSON. It probably is missing something that will still break a JS string, but its all I've found so far.
<cffunction name="JSClean" access="public" returntype="string" output="false">
<cfargument name="sString" type="string" required="true" />
<cfset var sReturn = REReplaceNoCase(Trim(arguments.sString), "\s", " ", "ALL") />
<cfloop list="\:':"":&" delimiters=":" index="x">
<cfset sReturn = ReplaceNoCase(sReturn, x, "\#x#", "ALL") />
</cfloop>
<cfreturn sReturn />
</cffunction>