core/helpers/StringHelper.php
public static function highlightWord($content, $word, $markup = '<b>%s</b>')
    {
        $word = (array) $word;
        $content = strip_tags($content);
        $latest = null;
        foreach ($word as $needle) {
            preg_match_all("/".preg_quote($needle, '/')."+/i", $content, $matches);
            if (is_array($matches[0]) && count($matches[0]) >= 1) {
                foreach ($matches[0] as $match) {
                    // ensure if a word is found twice we don't replace again.
                    if ($latest === $match) {
                        continue;
                    }
                    $content = str_replace($match, sprintf($markup, $match), $content);
                    $latest = $match;
                }
            }
        }

        return $content;
    }
public static function highlightWord($content, $word, $markup = '<b>%s</b>')
    {
        $word = (array) $word;
        $content = strip_tags($content);
        $latest = null;
        foreach ($word as $needle) {
            preg_match_all("/".preg_quote($needle, '/')."+/i", $content, $matches);
            if (is_array($matches[0]) && count($matches[0]) >= 1) {
                foreach ($matches[0] as $match) {
                    // ensure if a word is found twice we don't replace again.
                    if ($latest === $match) {
                        continue;
                    }
                    $content = str_replace($match, sprintf($markup, $match), $content);
                    $latest = $match;
                }
            }
        }

        return $content;
    }
public static function highlightWord ( $ content , $ word , $ markup = '<b>%s</b>' ) { $ word = ( array ) $ word ; $ content = strip_tags ( $ content ) ; $ latest = null ; foreach ( $ word as $ needle ) { preg_match_all ( "/" . preg_quote ( $ needle , '/' ) . "+/i" , $ content , $ matches ) ; if ( is_array ( $ matches [ 0 ] ) && count ( $ matches [ 0 ] ) >= 1 ) { foreach ( $ matches [ 0 ] as $ match ) { // ensure if a word is found twice we don't replace again. if ( $ latest === $ match ) { continue ; } $ content = str_replace ( $ match , sprintf ( $ markup , $ match ) , $ content ) ; $ latest = $ match ; } } } return $ content ; }
Highlight a word within a content.

Since version 1.0.14 an array of words to highlight is possible.

> This function IS NOT case sensitive!



@param string $content The content to find the word.
@param string $word The word to find within the content.
@param string $markup The markup used wrap the word to highlight.
@since 1.0.12
Highlight a word within a content .