2009
08.17

I needed a str_ireplace function for PHP4 (it’s a new in PHP5).  It does a case-insensitive string replace thing.


function str_ireplace4($needle, $replacement, $haystack) {
   $i = 0;
   while (($pos = strpos(strtolower($haystack),strtolower($needle), $i)) !== false) {
      $haystack = substr($haystack, 0, $pos) . $replacement.substr($haystack, $pos+strlen($needle));
      $i=$pos+strlen($replacement);
   }
   return $haystack;
}
 

1 comment so far

Add Your Comment
  1. v handy – thx