note 107179 added to function.str-ireplace

From: Date: Thu, 12 Jan 2012 13:45:07 +0000
Subject: note 107179 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-185611@lists.php.net to get a copy of this message
Apolagies, there was an error which I neglected, it always replaced with the first needle. Therefore, if you chose to highlight the letter 'A', and you have a capital A at the beggining and a lower case 'a' futher on in the string, it would place capitals through it. This revised version takes care of that. <?php function highlight($haystack, $needle) { //echo "<br>$haystack--$needle<br>"; preg_match_all("/$needle/i", $haystack, $match); $m = $match[0]; $replaced = ""; $exploded = preg_split("/$needle/i",$haystack); foreach($exploded as $e) if($e!=$exploded[count($exploded)-1]) {$replaced .= $e . "<font style=\"background-color:yellow\">" . $m[array_search($e,$exploded)] . "</font>";} else {$replaced .= $e;} return $replaced; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 213.122.162.226 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- https://master.php.net/note/edit/107179 Del: integrated -- https://master.php.net/note/delete/107179/integrated Del: useless -- https://master.php.net/note/delete/107179/useless Del: bad code -- https://master.php.net/note/delete/107179/bad+code Del: spam -- https://master.php.net/note/delete/107179/spam Del: non-english -- https://master.php.net/note/delete/107179/non-english Del: in docs -- https://master.php.net/note/delete/107179/in+docs Del: other reasons-- https://master.php.net/note/delete/107179 Reject -- https://master.php.net/note/reject/107179 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185611) next »