My apologies in advance if this too basic or there's a solution easily
found out there, but after lots of searching, I'm still lost.

 

I'm trying to build a regexp that would parse user-supplied text and
identify cases where HTML tags are left open or are not properly
matched-e.g., <b> tags without closing </b> tags. This is for a sort of
message board type of application, and I'd like to allow users to use
some HTML, but just would like to check to ensure that no stray tags are
input that would screw up the rest of the page's display. I'm new to
regular expressions, and the one below is as far as I've gotten. If
anyone has any suggestions, they'd be very much appreciated.

Thanks,

Andy

 

 

$suspect_tags = "b|i|u|strong|em|font|a|ol|ul|blockquote ";

$pattern = '/<(' . $suspect_tags . '[^>]*>)(.*)(?!<\/\1)/Ui';

if (preg_match($pattern,$_POST['entry'],$matches)) {

   //do something to report the unclosed tags

} else {

   echo 'Input looks fine. No unmatched tags.';

}

Reply via email to