Function which searches for a word in a text and highlights all the words which contain it
<p>This function searches for words (from the $words array) inside a text and highlights them.</p>

<pre><code>function highlightWords(Array $words, $text){ // Loop through array of words
    foreach($words as $word){ // Highlight word inside original text
        $text = str_replace($word, '&lt;span class="highlighted"&gt;' . $word . '&lt;/span&gt;', $text);
    }         
    return $text; // Return modified text
}
</code></pre>

<p>Here is the problem:</p>

<p>Lets say the $words = array("car", "drive");</p>

<p><strong>Is there a way for the function to highlight not only the word car, but also words which contain the letters "car" like: cars, carmania, etc.</strong></p>

<p>Thank you!</p>
