Let create a function first, let call it ‘ReplaceChar’
Function ReplaceChar (Text)
'Code here
End function
We can now just call this function each time we need to output data, like this:
Response.Write ReplaceChar(“This is a text to be formatted”)
Ok, now let’s start working on the function again. First we want to get rid of all the nasty HTML commands, which is done by the Server object's function HTMLEncode.
Function ReplaceChar (Text)
Dim Temp
Temp = Server.HTMLEncode(Text)
ReplaceChar = Temp
End function
Ok, now the user isn’t able to input any HTML, but we want some commands right? Most of the time tags like [ b] and [ /b] is used. But in this example i will use (b) and (/b) instead, you can use whatever you want.
Function ReplaceChar (Text)
Dim Temp
Temp = Server.HTMLEncode(Text)
Temp = Replace(Temp,”(b)”,”<b>”)
Temp = Replace(Temp,”(/b)”,”</b>”)
ReplaceChar = Temp
End function
There, now if we input “This is a <b>text</b> to be formatted” it would return that too, but the < as lt; and > as gt;. The average user wouldn’t notice that anyway. But if we input “This is a (b)text(/b) to be formatted” instead we would end up with a nice formatted text.
I hope you understand how to create those tags now! As a bonus I will give you a last example of basic tags, even with smileys =D See ya!
Function ReplaceChar (Text)
Dim Temp
Temp = Server.HTMLEncode(Text)
'New line
Temp = Replace(Temp,chr(13),"<br>")
'Horizontal line
Temp = Replace(Temp,"[line]","<hr>")
'Bold
Temp = Replace(Temp,"(b)","<b>")
Temp = Replace(Temp,"(/b)","</b>")
Temp = Replace(Temp,"(B)","<b>")
Temp = Replace(Temp,"(/B)","</b>")
'Italics
Temp = Replace(Temp,"(i)","<i>")
Temp = Replace(Temp,"(/i)","</i>")
Temp = Replace(Temp,"(I)","<i>")
Temp = Replace(Temp,"(/I)","</i>")
'Underline
Temp = Replace(Temp,"(u)","<u>")
Temp = Replace(Temp,"(/u)","</u>")
Temp = Replace(Temp,"(U)","<u>")
Temp = Replace(Temp,"(/U)","</u>")
‘Smileys
Temp = Replace(Temp,";smile;","<img src='images/smile.gif'>”)
Temp = Replace(Temp,";bad;","<img src='images/bad.gif'>”)
Temp = Replace(Temp,";rolleye;","<img src='images/rolleye.gif'>”)
ReplaceChar = Temp
End function
|