note 87006 added to function.str-ireplace

From: Date: Fri, 14 Nov 2008 14:44:21 +0000
Subject: note 87006 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-146526@lists.php.net to get a copy of this message
This function will highlight search terms (Key Words in Context). The difference between this one and the ones below is that it will preserve the original case of the search term as well. So, if you search for "american" but in the original string it is "American" it will retain the capital "A" as well as the correct case for the rest of the string. function kwic($str1,$str2) { $kwicLen = strlen($str1); $kwicArray = array(); $pos = 0; $count = 0; while($pos !== FALSE) { $pos = stripos($str2,$str1,$pos); if($pos !== FALSE) { $kwicArray[$count]['kwic'] = substr($str2,$pos,$kwicLen); $kwicArray[$count++]['pos'] = $pos; $pos++; } } for($I=count($kwicArray)-1;$I>=0;$I--) { $kwic = '<span class="kwic">'.$kwicArray[$I]['kwic'].'</span>'; $str2 = substr_replace($str2,$kwic,$kwicArray[$I]['pos'],$kwicLen); } return($str2); } ---- Server IP: 208.69.120.35 Probable Submitter: 71.61.80.27 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- https://master.php.net/note/edit/87006 Del: integrated -- https://master.php.net/note/delete/87006/integrated Del: useless -- https://master.php.net/note/delete/87006/useless Del: bad code -- https://master.php.net/note/delete/87006/bad+code Del: spam -- https://master.php.net/note/delete/87006/spam Del: non-english -- https://master.php.net/note/delete/87006/non-english Del: in docs -- https://master.php.net/note/delete/87006/in+docs Del: other reasons-- https://master.php.net/note/delete/87006 Reject -- https://master.php.net/note/reject/87006 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146526) next »