Skip to content

Instantly share code, notes, and snippets.

@pkdavies
Last active September 26, 2015 04:17
Show Gist options
  • Save pkdavies/1037649 to your computer and use it in GitHub Desktop.
Save pkdavies/1037649 to your computer and use it in GitHub Desktop.
MS Word "save as HTML" and HTML Purifier
<?php
if ($_POST['q']){
$dirty_html = $_POST['q'];
if (!$dirty_html) {
echo ('You must write some HTML!');
} else {
$config = HTMLPurifier_Config::createDefault();
$config->set('Core', 'Encoding', 'ISO-8859-1');
$config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');
$config->set('HTML', 'TidyLevel', 'heavy');
$config->set('Core','AcceptFullDocuments',true);
$config->set('HTML', 'Allowed', 'a[href|title],em,p,blockquote,img');
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify( $dirty_html );
echo $clean_html;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment