How to create a [Reusable] Function in [ASP Classic]
Creating a reusable function lets you use it anywhere in your code project.
I've been using this function for many years to help protect against [XSS injections] and have just used it in everything.
Copy the code below, copy and paste it into an empty page, and save it as Decoding.asp.
Encoding = Change the original characters.
Decoding = Change back to original characters.
[ASP Classic - Reusable Replace Function]
CFFCS | CarrzSynEdit: | ASP/VBScript

<%
' Encode (Change Characters)

Function Encoding(strEncoding) ' Name to URL.'

  strEncoding = Replace(strEncoding,"&#125;",")")
  strEncoding = Replace(strEncoding,"&#123;","(")
  strEncoding = Replace(strEncoding," ","_")
  Encoding = strEncoding
End Function

' Decode (Change Characters back to their original Characters.)

Function Decoding(strEncoding) ' Name to URL '

  strEncoding = Replace(strEncoding,")","&#125;")
  strEncoding = Replace(strEncoding,"(","&#123;")
  strEncoding = Replace(strEncoding,"_"," ")
  Decoding = strEncoding
End Function
%>

To reuse this function, add an INCLUDE FILE to all pages on which you want to use the function.
[ASP Classic - include file]
CFFCS | CarrzSynEdit: | ASP/VBScript

            <!--#include file="Decoding.asp"-->
<%
            Response.Write Encoding("Test (This is a test)"))
            Response.Write Decoding("Test {This is a test}"))
%>

The above example will
#1: replace the Parentheses with {[curly brackets]}
Copy
Search Site
Search Google
and add underscores where spaces are at.
Output: Test_{[This_is_a_test]}
Copy
Search Site
Search Google

#2: replace the {[curly brackets]}
Copy
Search Site
Search Google
with Parentheses and remove the underscores.
Output: Test (This is a test);
Copy
Search Site
Search Google
Other Articles Related to this Entry.