diff --git a/include/functions.php b/include/functions.php
index 8d09abf7b663f300ee1dc087c8fa824c20a10974..8ecdb71e5ae2e2f43b6173a06efece617efbb566 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -2801,7 +2801,8 @@
 	}
 
 	function strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes) {
-		$entries = $doc->getElementsByTagName("*");
+		$xpath = new DOMXPath($doc);
+		$entries = $xpath->query('//*');
 
 		foreach ($entries as $entry) {
 			if (!in_array($entry->nodeName, $allowed_elements)) {