note 83644 added to function.str-ireplace

From: Date: Thu, 05 Jun 2008 19:58:26 +0000
Subject: note 83644 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-140153@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 66.76.96.68 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- https://master.php.net/note/edit/83644 Del: integrated -- https://master.php.net/note/delete/83644/integrated Del: useless -- https://master.php.net/note/delete/83644/useless Del: bad code -- https://master.php.net/note/delete/83644/bad+code Del: spam -- https://master.php.net/note/delete/83644/spam Del: non-english -- https://master.php.net/note/delete/83644/non-english Del: in docs -- https://master.php.net/note/delete/83644/in+docs Del: other reasons-- https://master.php.net/note/delete/83644 Reject -- https://master.php.net/note/reject/83644 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140153) next »