RE: [PHP] preg_match question: locating unmatched HTML tags
| From: | John W. Holmes | Date: | Sat, 22 Feb 2003 06:05:45 +0000 |
| Subject: | RE: [PHP] preg_match question: locating unmatched HTML tags | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-136603@lists.php.net to get a copy of this message | ||
> 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.
Letting users enter HTML is a bad idea. Even if you only let them use
<b> tags, they can still put ONCLICK and mouseover effects for the bold
text to screw with your other users.
Use a BB style code, such as [b] for bold, [i] for italics, etc. This
way, you only match pairs and replace them with HTML and use
htmlentities on anything else. This way an unmatched [b] tag won't be
replaced with <b> and mess up your code.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/