|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-08-02 12:33 UTC] juhl at eisenstein dot dk
It would be extremely nice to have a case insensitive version of str_replace() so that you don't have to use the much slower eregi_replace() when you need to replace strings of mixed case. I believe a logical name for such a function would be stri_replace() If there are no current plans to implement such a feature, would a patch that implements it be accepted? Best regards, Jesper Juhl juhl@eisenstein.dk PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 23:00:01 2025 UTC |
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. .. txTry 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; }