I have a simple textarea where users can input a description for their product on my dummy system. I'm only allowing <b>
<u>
and <i>
tags, without any attributes using the following code:
$description = strip_tags($_POST['description'], "<b><u><i>");
$description = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i",'<$1$2>', $description);
My problem is when a tag is left without it's closing part, for example:
<b>This is a <i>Test
The <b>
and <i>
tags will apply to everything that comes after this part. Is there any reliable way to automatically close the tags?
What I want is for the tag to be closed on the end of the user input, but only if it was left open.