function remove_nodes( $html, array $selectors = array( '//comment()', '//script' ) )
{
$dom = new DOMDocument;
$dom->loadHtml( strval( $html ) );
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$xpath = new DOMXPath( $dom );
foreach( $selectors as $selector ) {
while ( $node = $xpath->query( $selector )->item( 0 ) ) {
// Remove selected tag from html string
$node->parentNode->removeChild( $node );
}
}
return $dom->saveHTML();
}