note 43582 deleted from function.str-replace by felipe
| From: | felipe@php.net | Date: | Sun, 23 Mar 2008 23:04:48 +0000 |
| Subject: | note 43582 deleted from function.str-replace by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137419@lists.php.net to get a copy of this message | ||
Note Submitter: aidan at php dot net
----
Here is a simple function for highlighting a needle in text. It is careful to not replace text in
HTML tags (unless specified).
http://aidanlister.com/repos/v/function.str_highlight.php
Example: The google method of highlighting
<?php
$text = "Here is some text with a search term";
$needle = "search term";
echo str_highlight($text, $needle);
?>
Output:
Here is some text with a <strong>search term</strong>