How to check whether content entered by a user in a custom form is valid HTML? I am trying to write a custom form in Drupal 6 which will check whether the content submitted by a user is valid HTML. 

If the content is valid I need to generate a txt file with HTML markup based on the content without a DTD.
You can probably do that with PHPTidy (PHP Module) and tidy_get_error_count