PHP-Fusion Development

highlight_words()

Highlights given words in string.

Versions: 9

highlight_words( array $words, string $subject ) : string

Parameters

$words (array) (Required) The words to highlight.

$subject (string) (Required) Text that contains a word (s) that should be highlighted.

Return Values

(string) Words highlighted in the string.

Examples

$words = ['lemon', 'banana'];
$subject = 'banana, apple, orange and lemon';
echo highlight_words($words, $subject);
// <span style='background-color:yellow;color:#333;font-weight:bold;padding-left:2px;padding-right:2px'>banana</span>, apple, orange and <span style='background-color:yellow;color:#333;font-weight:bold;padding-left:2px;padding-right:2px'>lemon</span>