Skip to content

Instantly share code, notes, and snippets.

@LiamBailey
Created September 24, 2015 15:21
Show Gist options
  • Save LiamBailey/e41b03e62368bb71c8ce to your computer and use it in GitHub Desktop.
Save LiamBailey/e41b03e62368bb71c8ce to your computer and use it in GitHub Desktop.
Strips out html (person importing content from Blogger)
<?php
$content = strip_tags($_POST['content'],"<p><br><a>");
lib_xml_use_internal_errors(true);
$DOM = new DOMDocument($content);
foreach($dom->getElementsByTagName($tagname) as $tag) {
if ($tag->hasAttributes()) {
foreach($tag->attributes as $attribute) {
if ($attribute->nodeName !== "href")
$tag->removeAttribute($attribute->nodeName);
}
}
}
$newContent = $dom->saveHTML();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment