 <p>For words (and I mean words not .com etc) this is simple</p> <p>You just want to pregmatch</p> <pre><code>'/\b' . $badword . '\b/' </code></pre> <p>\b is a word boundary</p> <p>for full stops you must escape them . to mean them literally (without \ they actually mean and character in a regex) so I would either write a function that looks for full stops and then adds a \ before them or just add them straight into your list with the \ already appended.</p>