I have this class, comes close to what you want. Feel free to modify, sorry I didn't have the time to comment it yet. I hope you can understand and use it :-) Anyway test it and see what it does.
class InseForm { function AllowedTags() { $allowed_tags = Array(); $allowed_tags['<a href>'] = '</a>'; $allowed_tags['<b>'] = '</b>'; $allowed_tags[] = '<br>'; $allowed_tags['<i>'] = '</i>'; $allowed_tags['<p>'] = '</p>'; return $allowed_tags; } function FilterTags($text) { $text = strip_tags($text, '<a><b><br><i><p>'); $text = ereg_replace("<a[^>]+href *= *([^ ]+)[^>]*>", "<a href=\\1>", $text); $text = ereg_replace("<(/?[[b]r?|i|p|a])[^>]*>", "<\\1>", $text); return htmlentities(stripslashes(trim($text))); } function CountAllowedTags($text) { $missing_tag = ''; foreach($this->AllowedTags() as $open_tag => $close_tag) { $nr_open_tags = substr_count(strtolower($text), $open_tag); $nr_close_tags = substr_count(strtolower($text), $close_tag); if ($nr_open_tags > $nr_close_tags) { $missing_tag .= 'A tag ' . htmlentities($open_tag) . ' was not closed!<br />'; } } if (!ereg("^[[:blank:]]*$", $missing_tag)) { return '<br /><span style="color:red;">' . $missing_tag . '</span>'; } else { return false; } } } -- Julio Nobrega. Tô chegando: http://www.inerciasensorial.com.br "David" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Hi all, > > I have a textarea which will containg info from the user. This then > needs to be parsed through something like htmlspecialchars() or > htmlentities(). > > The issue is that my system really needs to do the following: > > 1. Accept the info > 2. Check if there is any HTML syntax (<p>, etc) > 3. If YES: remove anything that might be harmful (eg FORM, etc) > 4. If NO: Add replace CR/LF with <BR> > > The idea is that normal formatting such as <b>, <i>, <u>, <a href> is > ok, but I do not want off illegal stuff. I want something a little like > Slashdot's stuff. > > Easy?? anyone know anything about this? > > Thanks > > David R > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php