Replace word phrases, honoring punctuation in php
<p>I have a custom php script that looks through text to find key phrases and replaces them using preg_replace, but I'm having trouble getting a clean regex for the job.</p>

<p>For example this sentence:</p>

<blockquote>
  <p>The fox jumped over the gated fence
  because it did not have hands to open
  the gate.</p>
</blockquote>

<p>I would want to bold all instances of <code>gate</code>, yet respect oddities like <code>gated</code>. And also preserve original capitalization too if possible.</p>

<p>So the end sentence would read like this:</p>

<blockquote>
  <p>The fox jumped over the gated fence
  because it did not have hands to open
  the <strong>gate</strong>.</p>
</blockquote>

<p>Here is the regular expression I've created myself, and you will see that it would not account for gate. because of the period following the word. And also the regex does not respect any original capitalization. </p>

<pre><code>$description  = preg_replace("/ $keyphrase /", " &lt;b&gt;$keyphrase&lt;/b&gt; ", $description, $limit);
</code></pre>
