highlight_phrase()

highlight_phrase($str, $phrase[, $tag_open = ''[, $tag_close = '']])

Parameters:
  • $str (string) – Input string
  • $phrase (string) – Phrase to highlight
  • $tag_open (string) – Opening tag used for the highlight
  • $tag_close (string) – Closing tag for the highlight
Returns:

String with a phrase highlighted via HTML

Return type:

string

Will highlight a phrase within a text string. The first parameter will contain the original string, the second will contain the phrase you wish to highlight. The third and fourth parameters will contain the opening/closing HTML tags you would like the phrase wrapped in.

Example:

$string = "Here is a nice text string about nothing in particular.";
echo highlight_phrase($string, "nice text", '<span style="color:#990000;">', '</span>');

The above code prints:

Here is a <span style="color:#990000;">nice text</span> string about nothing in particular.

Note

This function used to use the <strong> tag by default. Older browsers might not support the new HTML5 mark tag, so it is recommended that you insert the following CSS code into your stylesheet if you need to support such browsers:

mark {
        background: #ff0;
        color: #000;
};
doc_CodeIgniter
2016-10-15 16:32:25
Comments
Leave a Comment

Please login to continue.