26286 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
New York cop in
alleged
love-polyhedron
email hack spree
Penguin pays $75m
to settle ebook
price-fixing case
"Leccy car biz
baron Elon Musk:
Thanks for the
$500m, taxpayers...
Apple cored:
Samsung sells 10
million Galaxy S4
in a month
Brit spooks bugged
Edward VIII"s
phones, records
reveal
Virgin Media slides
fat 10Gbps pipes
into Murdoch"s
BSkyB
China"s exposed
crack cyberspy crew
dumps "most" of its
kit
SAP in search of
autistic software
engineers who
"think different"
George Soros pumps
£50m into
fibre-gobbling ISP
Hyperoptic
Microsoft and pals:
Save the global
economy by NOT
ripping us off
Slashdot
Kim Dotcom Wants
Money From Google,
Twitter For
2-Factor
Authentication
Meet Pidora, the
New Official Fedora
Remix For Raspberry
Pi
Terrorist Murder In
London Could Revive
Snooper"s Charter
One-Time Pad From
Caltech Offers
Uncrackable
Cryptography
First Government
Lawsuit Against a
Patent Troll
Why We Should
Celebrate Snapchat
and Encourage
Ephemeral
Communication
Teens, Social
Media, and Privacy
Physicists Create
Quantum Link
Between Photons
That Don"t Exist At
the Same Time
Missile Test
Creates Huge
Expanding Halo of
Light Over Hawaii
3D Printers For
Peace Contest
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 6759 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