Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I format users input (for a forum entry etc) ?

Formatting

How can I format users input (for a forum entry etc) ?

by  BigBadDave  Posted    (Edited  )
Ever wondered how you can convert www . my-link . com, into a click-able hyperlink, when a user submits data to a forum post etc ?


Here's how :


1.) Get the data

[color green]data = Request.Form("data")[/color]

2.) Get the data into an array of words (splitting up where a space occurs)

[color green]data = Split(data, " ")[/color]

3.) Get the length of the array

[color green]datalength = UBound(data)[/color]

4.) Replace www . with the full HTML href code (for every word in the array)

[color green]For x = 0 to datalength
If Instr(data(x),"www .") Then
data(x) = "<a href=""h ttp://" & data(x) & """ target=""_blank"">" & data(x) & "</a>"
End If
Next[/color]

5.) Join your string back up to output

[color green]data = Join(data, " ")[/color]

6.) Print final string

[color green]Response.Write data[/color]


Complete Code :

[color green]<%
data = Request.Form("data")
data = Split(data, " ")
datalength = UBound(data)
For x = 0 to datalength
If Instr(data(x),"www .") Then
data(x) = "<a href=""h ttp://" & data(x) & """ target=""_blank"">" & data(x) & "</a>"
End if
Next
data = Join(data, " ")
Response.Write data
%>[/color]


Regards

Big Bad Dave

[img http://www.byngdesigns.co.uk/tek-tips/spider.gif]
www.byngdesigns.co.uk

davidbyng@hotmail.com
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top