Page 1 of 1

Users not closing their tags on my forum...

Posted: Sun Jun 07, 2009 12:06 am
by Vael Victus
Hi, I've got my own forum software I've coded. When people don't close their tags in their posts (the [ i ] for example) it'll cause the rest of post - the signature and stuff - to be italicized also. So far my horrible solution I've come to is to just making a bunch of closing tags in the code which is an obviously poor way of dealing with it.

Do you guys have any idea how I could auto-close all tags?

Re: Users not closing their tags on my forum...

Posted: Sun Jun 07, 2009 12:42 am
by requinix
The way I think most applications deal with it is just not do the conversion.
That is, a opening/closing tag pair only gets handled if both the opening and closing tags are in place.

In terms of the code, rather than replace [i] with a <span> it replaces [i]text[/i] with <span>text</span>.

Re: Users not closing their tags on my forum...

Posted: Sun Jun 07, 2009 12:53 am
by Vael Victus
Oh that sounds like it's going into regular expression turf...

Do you know of an efficient way to check for all tags to have a closure? That'd be even better on the user. I'm good at PHP but I can't think of an efficient way to do it. That was my second option. :(

Re: Users not closing their tags on my forum...

Posted: Sun Jun 07, 2009 3:35 am
by requinix
Count the number of opening tags; count the number of closing tags. You can use substr_count for that.

BBCode implementations are traditionally done with regular expressions. Pretty simple ones even. It's not like you'd be admitting defeat to use them :o

Re: Users not closing their tags on my forum...

Posted: Sun Jun 07, 2009 9:38 am
by Weirdan
tasairis wrote:Count the number of opening tags; count the number of closing tags. You can use substr_count for that.
It will pass on overlapping tags: <b> some <i> text </b> here</i> even though it makes no sense from the html point of view.