note 90955 added to function.str-ireplace

From: Date: Mon, 18 May 2009 14:31:38 +0000
Subject: note 90955 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-155674@lists.php.net to get a copy of this message
The post below me had a problem with the highlighting function, for example when highlighting 'getmor' on the string getmore. It would find the e as not highlighted but then attempt to replace both e's in the string. I thought i'd provide my attempt at a decent highlighting function. function highlight($needle, $haystack) { $start = 0; while(@stripos($haystack, $needle, $start) !== false) { $get = stripos($haystack, $needle, $start); $get_text = substr($haystack, $get, strlen($needle)); $text_before = substr($haystack, 0, $get); $text_after = substr($haystack, ($get+strlen($needle))); $haystack = $text_before.'<font color="red">'.$get_text.'</font>'.$text_after; $start += ($get+strlen($needle)+25); } return $haystack; } ---- Server IP: 117.55.229.1 Probable Submitter: 58.161.112.175 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- https://master.php.net/note/edit/90955 Del: integrated -- https://master.php.net/note/delete/90955/integrated Del: useless -- https://master.php.net/note/delete/90955/useless Del: bad code -- https://master.php.net/note/delete/90955/bad+code Del: spam -- https://master.php.net/note/delete/90955/spam Del: non-english -- https://master.php.net/note/delete/90955/non-english Del: in docs -- https://master.php.net/note/delete/90955/in+docs Del: other reasons-- https://master.php.net/note/delete/90955 Reject -- https://master.php.net/note/reject/90955 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#155674) next »