我正在寻找一种使用ColdFusion编码字符串但不包括“。”的方法。
到目前为止,这是我尝试过的:
<!--- Test area --->
<cfset str="ChrisTilghmanFirstFlash.Eflv">
<cfset str1="Chris Tilghman First Flash.Eflv">
<cfset str2="Chris-Tilghman First_Flash.Eflv">
<cfset enc1 = urlEncodedFormat(str,"utf-8" )>
<cfset enc2 = urlEncodedFormat(str1,"utf-8")>
<cfset enc3 = urlEncodedFormat(str2,"utf-8")>
<cfoutput>#enc1#</cfoutput><br>
<cfoutput>#enc2#</cfoutput><br>
<cfoutput>#enc3#</cfoutput><br>
<!--- END test area --->
urlEncode utf-8其他也对“点”,“-”和“_”字符进行编码。如何防止这种情况?
最佳答案
这将为您解决:
<cfset str="ChrisTilghmanFirstFlash.Eflv">
<cfset str1="Chris Tilghman First Flash.Eflv">
<cfset str2="Chris-Tilghman First_Flash.Eflv">
<cfset enc1 = urlEncodedFormat(str,"utf-8" )>
<cfset enc2 = urlEncodedFormat(str1,"utf-8")>
<cfset enc3 = urlEncodedFormat(str2,"utf-8")>
<cfoutput>#replace(enc1, "%2E", ".", "ALL")#</cfoutput><br>
<cfoutput>#replace(enc2, "%2E", ".", "ALL")#</cfoutput><br>
<cfoutput>#replace(enc3, "%2E", ".", "ALL")#</cfoutput><br>