note 43582 modified in function.str-replace by aidan

From: Date: Sat, 03 Jul 2004 07:05:30 +0000
Subject: note 43582 modified in function.str-replace by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72358@lists.php.net to get a copy of this message
Here is a simple function for highlighting a needle in text. http://aidan.dotgeek.org/lib/?file=function.str_highlight.php For 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> ?> --was-- Here is a simple function for highlighting a needle in text. http://ircphp.com/users/imho/?file=function.str_highlight.php For 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> ?> You may also change the text to be added: <?php echo str_highlight($text, $needle, '[start]', '[end]'); // Output: Here is some text with a [start]search term[end] ?> Or, use it with an array of search terms: <?php $search = array('foo', 'bar'); $text = "Who is foo and who is bar?"; echo str_highlight($text, $search); // Output: Who is <strong>foo</strong> and who is <strong>bar</strong>? ?> Hope someone finds this useful. http://php.net/manual/en/function.str-replace.php

« previous php.notes (#72358) next »