Check for each text node whether or not it exists in DataBase, if it does then add a class to its Element node.
I have tried do it the following way :
function extractText($node) {
    if (XML_TEXT_NODE === $node->nodeType || XML_CDATA_SECTION_NODE === $node->nodeType) {
// am considering that Login is the word that exists in DB
            if ($node->nodeValue == "Login"): 
                $node->setAttribute("class", "translated");
                return $node->nodeName;
            endif;
        } else if (XML_ELEMENT_NODE === $node->nodeType || XML_DOCUMENT_NODE === $node->nodeType
                || XML_DOCUMENT_FRAG_NODE === $node->nodeType) {
            if ('script' === $node->nodeName || 'style' === $node->nodeName)
                return '';
        $text = '';
        foreach ($node->childNodes as $childNode) {
            $text .= extractText($childNode);
        }
        return $text;
    }
}
$doc = new DomDocument;
$doc->loadHTMLFile('test.html');
//var_dump(extractText($doc->getElementsByTagName('body')->item(0)));
echo extractText($doc->getElementsByTagName('body')->item(0));
But it gives Error message.
Fatal error: Call to undefined method DOMText::setAttribute()
 
    