Forum Moderators: open

Message Too Old, No Replies

Using [url] & [/url], like this form.

I got most of it done.

         

dnbjason

6:25 pm on Jul 29, 2003 (gmt 0)

10+ Year Member


I'm trying to use the "Style Codes" like this website in my program and I'm stuck on part of it.

What I have below is what I wrote so far and works great, but it is just a replacer. I want to use [url] & [/url] and haven't figured out how to do it. I guess I need to capture the characters between the two tags.

<%
Dim text1

text1 = Request.Form("body")
Response.Write(TextConvert(text1))

FUNCTION TextConvert(text)

'Basic HTML Convert
symbols = "[b],<b>;[/b],</b>;[i],<i>;[/i],</i>;[u],<u>;[/u],</u>;[center],<center>;[/center],</center>;[sup],<sup>;[/sup],</sup>;[sub],<sub>;[/sub],</sub>;[1],<font size=1>;[/1],</font>;[2],<font size=2>;[/2],</font>"

FOR EACH symbol in Split(symbols, ";")
sym = Split(symbol, ",")
text = Replace(text, sym(0), sym(1))
NEXT

'Keep Breaks
text = Replace(text, chr(10) & chr(13), "<br>")
TextConvert = text

END FUNCTION

%>

Any ideals? Is there an easier way of doing it?

garann

7:15 pm on Jul 29, 2003 (gmt 0)

10+ Year Member



Would this work? (Seperating the '>' from the rest of the tag, so attributes ought to be ignored. But it makes ']' a problematic character, outside a tag.)


FUNCTION TextConvert(text)

'Basic HTML Convert
symbols = "[b,<b;[/b,</b;[i,<i;[/i,</i;[u,<u;[/u,</u;[center,<center;[/center,</center;[sup,<sup;[/sup,</sup;[sub,<sub;[/sub,</sub;[1,<font size=1;[/1,</font;[2,<font size=2;[/2,</font"

symbols = symbols & ";],>"

...

If you're working with .NET, you might be better served using the RegEx.Replace(...) method. That way, you don't have to list out all the tags, either - you can just go through your resultant string and replace illegal tags (maybe <script>). Don't know if this method is available in ASP?

hth,
g.

dmorison

7:23 pm on Jul 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



URL replacements etc. are generally done with regular expression functions.

You should also count the open and close instances of each supported tag so that noone can screw with the HTML for the rest of the page, for example by opening a [b]bold tag but not closing it.