Users not closing their tags on my forum...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Vael Victus
Forum Newbie
Posts: 24
Joined: Wed Jun 03, 2009 9:29 am

Users not closing their tags on my forum...

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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>.
Vael Victus
Forum Newbie
Posts: 24
Joined: Wed Jun 03, 2009 9:29 am

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

Post 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. :(
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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

Post 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.
Post Reply