我们目前一直在使用我们从 cflib.org 使用的 UDF,虽然它是一个很棒的 UDF,可以将字符串更改为美观,但我们似乎无法弄清楚如何使其允许尾随“。” 如果输入,则在字符串的末尾。
<cffunction name="friendlyURL" output="false" access="public" returntype="string" hint="returns a URL safe string">
<cfargument name="string" default="" type="string">
<cfscript>
var returnString = arguments.string;
var InvalidChars = "à,ô,d,?,ë,š,o,ß,a,r,?,n,a,k,s,?,n,l,h,?,ó,ú,e,é,ç,?,c,õ,?,ø,g,t,?,e,c,s,î,u,c,e,w,?,u,c,ö,è,y,a,l,u,u,s,g,l,ƒ,ž,?,?,å,ì,ï,?,t,r,ä,í,r,ê,ü,ò,e,ñ,n,h,g,d,j,ÿ,u,u,u,t,ý,o,â,l,?,z,i,ã,g,?,o,i,ù,i,z,á,û,þ,ð,æ,µ,e,À,Ô,D,?,Ë,Š,O,A,R,?,N,A,K,S,?,N,L,H,?,Ó,Ú,E,É,Ç,?,C,Õ,?,Ø,G,T,?,E,C,S,Î,U,C,E,W,?,U,C,Ö,È,Y,A,L,U,U,S,G,L,ƒ,Ž,?,?,Å,Ì,Ï,?,T,R,Ä,Í,R,Ê,Ü,Ò,E,Ñ,N,H,G,Ð,J,Ÿ,U,U,U,T,Ý,O,Â,L,?,Z,I,Ã,G,?,O,I,Ù,I,Z,Á,Û,Þ,Ð,Æ,?,E";
var ValidChars = "a,o,d,f,e,s,o,ss,a,r,t,n,a,k,s,y,n,l,h,p,o,u,e,e,c,w,c,o,s,o,g,t,s,e,c,s,i,u,c,e,w,t,u,c,oe,e,y,a,l,u,u,s,g,l,f,z,w,b,a,i,i,d,t,r,ae,i,r,e,ue,o,e,n,n,h,g,d,j,y,u,u,u,t,y,o,a,l,w,z,i,a,g,m,o,i,u,i,z,a,u,th,dh,ae,u,e,A,O,D,F,E,S,O,A,R,T,N,A,K,S,Y,N,L,H,P,O,U,E,E,C,W,C,O,S,O,G,T,S,E,C,S,I,U,C,E,W,T,U,C,Oe,E,Y,A,L,U,U,S,G,L,F,Z,W,B,A,I,I,D,T,R,Ae,I,R,E,Ue,O,E,N,N,H,G,D,J,Y,U,U,U,T,Y,O,A,L,W,Z,I,A,G,M,O,I,U,I,Z,A,U,TH,Dh,Ae,U,E";
// trim the string
returnString = Trim(returnString);
returnString = StripCR(returnString);
// replace known characters with the corresponding safe characters
returnString = ReplaceList(returnString,InvalidChars,ValidChars);
// replace unknown characters in the x00-x7F-range with x's
returnString = returnString.ReplaceAll('[^\x00-\x7F]','x');
// Replace one or many comma with a dash
returnString = returnString.ReplaceAll(',+', '-');
// Other substitutions
returnString = Replace(returnString, "%", "percent","ALL");
returnString = Replace(returnString, "&", " and ","ALL");
returnString = Replace(returnString, "&", " and ","ALL");
returnString = returnString.ReplaceAll('[:,/]', '-');
// Replace one or more whitespace characters with a dash
returnString = returnString.ReplaceAll('[\s]+', '-');
// And everything else simply has to go
returnString = returnString.ReplaceAll('[^A-Za-z0-9\/-]','');
// finally replace multiple dash characters with just one
returnString = returnString.ReplaceAll('-+','-');
// we're done
return returnString;
</cfscript>
</cffunction>
我的正则表达式,不是很好,我已经花了几个小时修补它,但似乎仍然无法弄清楚如何让它有一个尾随的“。” 如果输入一个。