note 83644 deleted from function.str-ireplace by danbrown

From: Date: Tue, 04 Sep 2012 14:26:15 +0000
Subject: note 83644 deleted from function.str-ireplace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190486@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- I modified a script from notes on the eregi_replace() function page. This is a highlight script that worked good for me. $text - is the text to search $words - are the words to highlight (search text) $the_place - is so that you can tell your users what "area" was searched. <?php function highlight_this($text, $words, $the_place) { $words = trim($words); $wordsArray = explode(' ', $words); foreach($wordsArray as $word) { if(strlen(trim($word)) != 0) $text = str_ireplace($word, "<span class=\"highlight\">".strtoupper($word)."</span>", $text, $count); } //added to show how many keywords were found echo "<br><div class=\"emphasis\">A search for <strong>" . $words. "</strong> found <strong>" . $count . "</strong> matches within the " . $the_place. ".</div><br>"; //end script modification return $text; } ?>

« previous php.notes (#190486) next »