HTMLPurifier.
Download it here: http://htmlpurifier.org/
Include it:
include 'path/to/HTMLPurifier.auto.php';
Use it:
$config = HTMLPurifier_Config::createDefault();
$config->set('Core', 'Encoding', 'UTF-8');
$config->set('XHTML', 'Doctype', 'XHTML 1.0 Strict');
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify( $dirty_html );
And sleep well knowing there are no XSS attacks in HTML cleaned like this.
People suggesting mysql_real_escape_string() probably didn't get your question (or i didn't), you were asking how to filter HTML markup from a WYSIWYG editor so it can be safely stored in a database.
mysql_real_escape_string() is relevant as a protection against SQL injection but prepared statements (google "PDO") are better for that.