private function stripComments(\DOMDocument $source) { $xpath = new \DOMXPath($source); foreach ($xpath->query('//comment()') as $commentNode) { $commentNode->parentNode->removeChild($commentNode); } return $source; }