ID: 5919 Comment by: php_pp at yahoo dot com Reported By: juhl at eisenstein dot dk Status: Closed Bug Type: Feature/Change Request Operating System: Slackware Linux 7.0 PHP Version: 4.3.0 New Comment:
Try this ... function stri_replace($search, $subject, $replace=false){ $textn=$subject; $texti=strtolower($subject); $wordi=strtolower($search); $recd=array(); $len=strlen($wordi); while(is_integer($pos=strpos($texti,$wordi))){ $rec["str"]=substr($textn,$pos,$len); $rec["pre"]=substr($textn,0,$pos); $recd[]=$rec; $cut=$pos+$len; $texti=substr($texti,$cut); $textn=substr($textn,$cut); } for($i=0;$i<count($recd);$i++){ if(!$replace) $replace="<b>".$recd[$i]["str"]."</b>"; $ntext=$ntext.$recd[$i]["pre"].$replace; } $ntext.=$textn; return $ntext; } Previous Comments: ------------------------------------------------------------------------ [2003-03-21 03:20:51] ruud at phpjunk dot nl Damn.. i need this function.. i've fixed it with this: function highlight_search_string ($needle, $haystack, $start, $end) { $parts = explode( strtolower($needle), strtolower($haystack)); $pos = 0; foreach($parts as $key => $part) { $parts[ $key ] = substr($haystack, $pos, strlen($part)); $pos += strlen($part); $parts[ $key ] .= $start.substr($haystack, $pos, strlen($needle)).$end; $pos += strlen($needle); } return(join('', $parts)); } but that's not everything.. i hope this feat will be made in the new version of php. .. tx ------------------------------------------------------------------------ [2003-03-18 04:18:33] cvr at solcon dot org This feature would be very helpfull!! ------------------------------------------------------------------------ [2003-01-29 23:02:02] [EMAIL PROTECTED] This bug has been fixed in CVS. In case this was a PHP problem, snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites in short time. Thank you for the report, and for helping us make PHP better. Only took 29 months to do it too! ------------------------------------------------------------------------ [2002-12-28 18:38:40] mike dot h at iwmi dot com It would be extreamly great if some one....perhaps some one who volunteered might submit a patch to impliment this, 137 votes already, why can't we get some type of a feature voting system, to vote for the things that are the most important to those who don't have the skills, or perhaps time, or money to do these themselves. ------------------------------------------------------------------------ [2002-11-01 12:59:56] php at bkjproductions dot com What about just adding a parameter to the existing function, rather than making a whole new function? You could just put "sensitive" or "insensitive" (maybe "callous?") or something on the end: str_replace($a, $b, $c, "sensitive") I think that some other languages (maybe the ill-fated Oracle Media Objects) have that. Another parameter could be "match" so that if $a="street" $b= "avenue" $c= "1313 Mockingbird Street" the result would be "1313 Mockingbird Avenue" the idea being that the search routine realized that Street was capitalized, so therefore Avenue should match the case. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/5919 -- Edit this bug report at http://bugs.php.net/?id=5919&edit=1