note 83643 added to function.eregi-replace

From: Date: Thu, 05 Jun 2008 19:56:05 +0000
Subject: note 83643 added to function.eregi-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-140152@lists.php.net to get a copy of this message
I modified the script from the note below this one so that you could show how many matches were found. I know this should probably be posted in the str_ireplace() area, so I will post it there afterwards. $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; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 66.76.96.68 ---- Manual Page -- http://www.php.net/manual/en/function.eregi-replace.php Edit -- https://master.php.net/note/edit/83643 Del: integrated -- https://master.php.net/note/delete/83643/integrated Del: useless -- https://master.php.net/note/delete/83643/useless Del: bad code -- https://master.php.net/note/delete/83643/bad+code Del: spam -- https://master.php.net/note/delete/83643/spam Del: non-english -- https://master.php.net/note/delete/83643/non-english Del: in docs -- https://master.php.net/note/delete/83643/in+docs Del: other reasons-- https://master.php.net/note/delete/83643 Reject -- https://master.php.net/note/reject/83643 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140152) next »