Hi,

Saturday, February 22, 2003, 12:35:15 PM, you wrote:
AC> My apologies in advance if this too basic or there's a solution easily
AC> found out there, but after lots of searching, I'm still lost.

 

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

AC> Thanks,

AC> Andy

 

 

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

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

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

AC>    //do something to report the unclosed tags

AC> } else {

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

AC> }

The simplest is just to add </b></i></textarea></whatever else you allow> directly to 
the end of their
message, may not be technically correct but it won't do any harm either :)

-- 
regards,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to