note 83322 modified in function.eregi-replace by yannick
| From: | yannick@php.net | Date: | Sun, 25 May 2008 14:46:17 +0000 |
| Subject: | note 83322 modified in function.eregi-replace by yannick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139746@lists.php.net to get a copy of this message | ||
Hi everyone.
I saw a lot of highlighting functions, but no one was simple... maybe I missed a part of discussion
?
Anyway, I think this function is the easiest:
<?php
function highlight($text, $words) {
$words = trim($words);
$wordsArray = explode(' ', $words);
foreach($wordsArray as $word) {
if(strlen(trim($word)) != 0)
$text = eregi_replace($word, '<span
class="highlight">\\0</span>', $text);
}
return $text;
}
?>
--was--
Hi everyone.
I saw a lot of highlighting functions, but no one was simple... maybe I missed a part of discussion
?
Anyway, I think this function is the easiest:
function highlight($text, $words) {
$words = trim($words);
$wordsArray = explode(' ', $words);
foreach($wordsArray as $word) {
if(strlen(trim($word)) != 0)
$text = eregi_replace($word, '<span
class="highlight">\\0</span>', $text);
}
return $text;
}
http://php.net/manual/en/function.eregi-replace.php