public function replace(DOMText $node) {
    if (preg_match($this->_pattern, $node->nodeValue)) {
      // split using the pattern, but capture the delimiter strings
      $parts = preg_split(
        $this->_pattern, $node->nodeValue, -1, PREG_SPLIT_DELIM_CAPTURE
      );
      $items = [];
      foreach ($parts as $part) {
        $string = strtolower($part);
        if (isset($this->_highlights[$string])) {
          $span = $node->ownerDocument->createElement('span');
          $items[] = FluentDOM($span)
            ->addClass($this->_highlights[$string])
            ->text($part)
            ->item(0);
        } else {
          $items[] = $node->ownerDocument->createTextNode($part);
        }
      }
      // replace the text node
      FluentDOM($node)->replaceWith($items);
    }
  }
public function replace(DOMText $node) {
    if (preg_match($this->_pattern, $node->nodeValue)) {
      // split using the pattern, but capture the delimiter strings
      $parts = preg_split(
        $this->_pattern, $node->nodeValue, -1, PREG_SPLIT_DELIM_CAPTURE
      );
      $items = [];
      foreach ($parts as $part) {
        $string = strtolower($part);
        if (isset($this->_highlights[$string])) {
          $span = $node->ownerDocument->createElement('span');
          $items[] = FluentDOM($span)
            ->addClass($this->_highlights[$string])
            ->text($part)
            ->item(0);
        } else {
          $items[] = $node->ownerDocument->createTextNode($part);
        }
      }
      // replace the text node
      FluentDOM($node)->replaceWith($items);
    }
  }
public function replace ( DOMText $ node ) { if ( preg_match ( $ this -> _pattern , $ node -> nodeValue ) ) { // split using the pattern, but capture the delimiter strings $ parts = preg_split ( $ this -> _pattern , $ node -> nodeValue , - 1 , PREG_SPLIT_DELIM_CAPTURE ) ; $ items = [ ] ; foreach ( $ parts as $ part ) { $ string = strtolower ( $ part ) ; if ( isset ( $ this -> _highlights [ $ string ] ) ) { $ span = $ node -> ownerDocument -> createElement ( 'span' ) ; $ items [ ] = FluentDOM ( $ span ) -> addClass ( $ this -> _highlights [ $ string ] ) -> text ( $ part ) -> item ( 0 ) ; } else { $ items [ ] = $ node -> ownerDocument -> createTextNode ( $ part ) ; } } // replace the text node FluentDOM ( $ node ) -> replaceWith ( $ items ) ; } }
Check text node content for strings, split them by the strings, and replace strings with
a node structure. By using the DOM functions and not a somple replace, we can avoid
any problems with encodings.

@param DOMText $node
Check text node content for strings split them by the strings and replace strings with a node structure . By using the DOM functions and not a somple replace we can avoid any problems with encodings .