/** * Apply highlight to words in body text * * Surround occurances of words in body with pre in front and post * behing. Considers only occurances of words outside of HTML tags. * * @param mixed $words words to highlight * @param string $body body of html text to highlight * @param string $pre string to begin a highlight * @param string $post string to end a highlight * * @return string highlighted body */ public static function apply($words, $body, $pre = '<strong>', $post = '</strong>') { if (!is_array($words)) { $words = str_replace(' ', ' ', $words); $words = explode(' ', $words); } foreach ($words as $word) { $body = Highlighter::splitOnTag($word, $body, $pre, $post); } return $body; }