protected function _highlightNodeRecursive(DOMNode $contextNode, $wordsToHighlight, $callback, $params)
    {
        $textNodes = array();

        if (!$contextNode->hasChildNodes()) {
            return;
        }

        foreach ($contextNode->childNodes as $childNode) {
            if ($childNode->nodeType == XML_TEXT_NODE) {
                // process node later to leave childNodes structure untouched
                $textNodes[] = $childNode;
            } else {
                // Process node if it's not a script node
                if ($childNode->nodeName != 'script') {
                    $this->_highlightNodeRecursive($childNode, $wordsToHighlight, $callback, $params);
                }
            }
        }

        foreach ($textNodes as $textNode) {
            $this->_highlightTextNode($textNode, $wordsToHighlight, $callback, $params);
        }
    }
protected function _highlightNodeRecursive(DOMNode $contextNode, $wordsToHighlight, $callback, $params)
    {
        $textNodes = array();

        if (!$contextNode->hasChildNodes()) {
            return;
        }

        foreach ($contextNode->childNodes as $childNode) {
            if ($childNode->nodeType == XML_TEXT_NODE) {
                // process node later to leave childNodes structure untouched
                $textNodes[] = $childNode;
            } else {
                // Process node if it's not a script node
                if ($childNode->nodeName != 'script') {
                    $this->_highlightNodeRecursive($childNode, $wordsToHighlight, $callback, $params);
                }
            }
        }

        foreach ($textNodes as $textNode) {
            $this->_highlightTextNode($textNode, $wordsToHighlight, $callback, $params);
        }
    }
protected function _highlightNodeRecursive ( DOMNode $ contextNode , $ wordsToHighlight , $ callback , $ params ) { $ textNodes = array ( ) ; if ( ! $ contextNode -> hasChildNodes ( ) ) { return ; } foreach ( $ contextNode -> childNodes as $ childNode ) { if ( $ childNode -> nodeType == XML_TEXT_NODE ) { // process node later to leave childNodes structure untouched $ textNodes [ ] = $ childNode ; } else { // Process node if it's not a script node if ( $ childNode -> nodeName != 'script' ) { $ this -> _highlightNodeRecursive ( $ childNode , $ wordsToHighlight , $ callback , $ params ) ; } } } foreach ( $ textNodes as $ textNode ) { $ this -> _highlightTextNode ( $ textNode , $ wordsToHighlight , $ callback , $ params ) ; } }
highlight words in content of the specified node

@param DOMNode  $contextNode
@param array    $wordsToHighlight
@param callback $callback         Callback method, used to transform (highlighting) text.
@param array    $params           Array of additionall callback parameters (first non-optional parameter is a text to transform)
highlight words in content of the specified node