26288 total geeks with 3498 solutions
Recent challengers:
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
MaxMouse
It's Friday... That's good enough for me!
CodeX
non stop lolz here but thats soon to end thanks to uni, surely the rest of the world is going good?
stabat
how things are going guys? Here... boring...
CodeX
I must be going wrong on the password lengths then, as long as it was done on ECB
MaxMouse
lol... the key is in hex (MD5: of the string "doit" without the "'s) and is in lower case. Maybe i should have submitted this as a challenge!

Donate
Donate and help us fund new challenges
Donate!
Due Date: May 31
May Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
Experts: Network
security
deteriorating,
privacy a lost
cause
Internet cafés
declared "illegal
businesses" in Ohio
SAP shuffles execs
to chase cloud
success
AT&T adds 61¢
"Mobility
Administrative Fee"
for users
Microsoft caves to
Google, pulls
YouTube app from
WinPhone Store
Amazon expands
Appstore reach,
gives devs more
user data
Now it gets
serious: Fracking
could RUIN BEER
Reports: New Xbox
could DOOM
second-hand games
market
Industry execs:
Network admins are
an endangered
species
Wikileaks leaks
documentary script
about Wikileaks
Slashdot
African Soil Mapped
For the Very First
Time
BeagleBone Black
Ships With New
Linux 3.8 Kernel
Google Releases
Glass Factory
System Image,
Rooted Bootloader
White House: Use
Metric If You Want,
We Don"t Care
A Snapshot of the
Inside of an Atom
WHO: Intellectual
Property Claims
Hindering Research
On Deadly Novel
Coronavirus
Google Plans
Wireless Networks
In Emerging Markets
Intel Claims
Haswell
Architecture Offers
50% Longer Battery
Life vs. Ivy Bridge
Facebook Cancels UK
Launch of HTC First
Judge Thinks Apple
Will Lose E-Book
Price-Fixing Case
Article viewer

Basic Forum Tags



Written by:eXt
Published by:aton
Published on:2003-12-12 19:15:18
Topic:ASP
Search OSI about ASP.More articles by eXt.
 viewed 6763 times send this article printer friendly

Digg this!
    Rate this article :
Ever created a forum, or something else that would output text that someone else wrote? Then you probably know it isn’t a good idea to let the user input HTML directly, but you might want them to style the text a bit too. This article will show you a basic way to do this.

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


Did you like this article? There are hundreds more.

Comments:
<none>
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:



     
Your Ad Here
 
Copyright Open Source Institute, 2006