Closing tags (<b>, <i>) in user-inputted fields

Soldato
Joined
27 Dec 2005
Posts
17,316
Location
Bristol
I'm currently working on a fairly complex dbb, and in one such table/field is a description entered by the user. I want to allow basic HTML (bold, italic, line break) and I'm doing this by replacing all <'s and >'s with ['s and ]'s respectively to disallow all HTML, and then on output converting all [.b]'s into <b>'s and so on.

However I'm wondering how to close tags that are open? A botched way would obviously be just to stick a </b> and </i> at the end of every output, but that's not really good form and won't prevent multiple open tags.

My current thoughts of how to do this are to count the number of [.b]'s and [/b]'s in the var, and if [.b] > [/b] then stick a [/b] on the end for each. Is there an easier/better/simpler way?
 
Back
Top Bottom