title: XPath contains() Search for Exact Match
body: <p>Is it possible to search a DOMDocument object with fn:contains and return true on only an exact match for a word?</p>
  
  <p>I have a text replacement snippet that I did not write myself that does internal link replacements for keywords.  But as written it also replaces partial words instead of only the full word.</p>
  
  <p>Here is the snippet:</p>
  
  <pre><code>$autolinks = $this-&gt;config-&gt;get('autolinks');
  if (isset($autolinks) &amp;&amp; (strpos($this-&gt;data['description'], 'iframe') == false) 
          &amp;&amp; (strpos($this-&gt;data['description'], 'object') == false)):
      $xdescription = mb_convert_encoding(html_entity_decode($this-&gt;data['description'], ENT_COMPAT, "UTF-8"), 'HTML-ENTITIES', "UTF-8"); 
      libxml_use_internal_errors(true);
      $dom = new DOMDocument;             
      $dom-&gt;loadHTML('&lt;div&gt;'.$xdescription.'&lt;/div&gt;');             
      libxml_use_internal_errors(false);
      $xpath = new DOMXPath($dom);
      foreach ($autolinks as $autolink):
          $keyword    = $autolink['keyword'];
          $xlink  = mb_convert_encoding(html_entity_decode($autolink['link'], ENT_COMPAT, "UTF-8"), 'HTML-ENTITIES', "UTF-8");
          $target     = $autolink['target'];
          $tooltip    = isset($autolink['tooltip']);                          
          $pTexts     = $xpath-&gt;query(
              sprintf('///text()[contains(., "%s")]', $keyword)
          );
          foreach ($pTexts as $pText):
              $this-&gt;parseText($pText, $keyword, $dom, $xlink, $target, $tooltip);
          endforeach;
      endforeach;
      $this-&gt;data['description'] = $dom-&gt;saveXML($dom-&gt;documentElement);
  endif;
  </code></pre>
  
  <p>In example:</p>
  
  <p>If my keyword is "massage" *<em>massage</em>*r is partially matched and converted to a link, when only the whole word massage should be converted, not massager.</p>