title: PHP Regex for whole words only
body: <p>I have the following code:</p>
  
  <pre><code>function mmh_links($message){
      ini_set('auto_detect_line_endings','1');
      $row = 1;
      if (($handle = fopen(realpath(dirname(__FILE__))."/mmh_replace.csv", "r")) !== FALSE) {
          while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
              $message = preg_replace("/({$data[0]}(?![^&gt;&lt;]*?(?:&gt;|&lt;\/a)))/i","&lt;a href=\"{$data[1]}\" class=\"postlink\"&gt;$1&lt;/a&gt;",$message,1);
          }
          fclose($handle);
      }
  
      return $message;    
  }
  </code></pre>
  
  <p>Which looks for specific keywords from a CSV file and surround them by a link given in the CSV file as well. Additionally, it makes sure it only replaces each keyword only once, and makes sure it doesn't replace keywords that are already within links, and it is case insensitive. All good so far.</p>
  
  <p>Now I want to limit to search to "whole words", meaning I don't want "test" to catch "xxxtestxxx".</p>
  
  <p>What's my best option to do this, while keeping all the rules I wrote before?</p>