Re: preg_match question: locating unmatched HTML tags

From: Date: Sat, 22 Feb 2003 23:52:17 +0000
Subject: Re: preg_match question: locating unmatched HTML tags
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-136689@lists.php.net to get a copy of this message
you could consider configuring a prebuild html editor (just WYSIWYG) without any problems of users having to write code at all check out: http://www.interactivetools.com/products/htmlarea/ "Andy Crain" <crain@fuse.net> wrote in message news:004901c2da1b$0b3fd4e0$865244d8@NEWSLOGIC... > 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.'; > > } > >

« previous php.general (#136689) next »