public static function str_ireplace($search, $replace, $str, $count = null)
    {
        if (! is_array($search)) {
            $slen = strlen($search);
            $lendif = strlen($replace) - $slen;
            if ($slen === 0) {
                return $str;
            }

            $search = AnHelperString::strtolower($search);

            $search = preg_quote($search, '/');
            $lstr = AnHelperString::strtolower($str);
            $i = 0;
            $matched = 0;
            while (preg_match('/(.*)'.$search.'/Us', $lstr, $matches)) {
                if ($i === $count) {
                    break;
                }
                $mlen = strlen($matches[0]);
                $lstr = substr($lstr, $mlen);
                $str = substr_replace($str, $replace, $matched+strlen($matches[1]), $slen);
                $matched += $mlen + $lendif;
                $i++;
            }
            return $str;
        } else {
            foreach (array_keys($search) as $k) {
                if (is_array($replace)) {
                    if (array_key_exists($k, $replace)) {
                        $str = AnHelperString::str_ireplace($search[$k], $replace[$k], $str, $count);
                    } else {
                        $str = AnHelperString::str_ireplace($search[$k], '', $str, $count);
                    }
                } else {
                    $str = AnHelperString::str_ireplace($search[$k], $replace, $str, $count);
                }
            }
            return $str;
        }
    }
public static function str_ireplace($search, $replace, $str, $count = null)
    {
        if (! is_array($search)) {
            $slen = strlen($search);
            $lendif = strlen($replace) - $slen;
            if ($slen === 0) {
                return $str;
            }

            $search = AnHelperString::strtolower($search);

            $search = preg_quote($search, '/');
            $lstr = AnHelperString::strtolower($str);
            $i = 0;
            $matched = 0;
            while (preg_match('/(.*)'.$search.'/Us', $lstr, $matches)) {
                if ($i === $count) {
                    break;
                }
                $mlen = strlen($matches[0]);
                $lstr = substr($lstr, $mlen);
                $str = substr_replace($str, $replace, $matched+strlen($matches[1]), $slen);
                $matched += $mlen + $lendif;
                $i++;
            }
            return $str;
        } else {
            foreach (array_keys($search) as $k) {
                if (is_array($replace)) {
                    if (array_key_exists($k, $replace)) {
                        $str = AnHelperString::str_ireplace($search[$k], $replace[$k], $str, $count);
                    } else {
                        $str = AnHelperString::str_ireplace($search[$k], '', $str, $count);
                    }
                } else {
                    $str = AnHelperString::str_ireplace($search[$k], $replace, $str, $count);
                }
            }
            return $str;
        }
    }
public static function str_ireplace ( $ search , $ replace , $ str , $ count = null ) { if ( ! is_array ( $ search ) ) { $ slen = strlen ( $ search ) ; $ lendif = strlen ( $ replace ) - $ slen ; if ( $ slen === 0 ) { return $ str ; } $ search = AnHelperString :: strtolower ( $ search ) ; $ search = preg_quote ( $ search , '/' ) ; $ lstr = AnHelperString :: strtolower ( $ str ) ; $ i = 0 ; $ matched = 0 ; while ( preg_match ( '/(.*)' . $ search . '/Us' , $ lstr , $ matches ) ) { if ( $ i === $ count ) { break ; } $ mlen = strlen ( $ matches [ 0 ] ) ; $ lstr = substr ( $ lstr , $ mlen ) ; $ str = substr_replace ( $ str , $ replace , $ matched + strlen ( $ matches [ 1 ] ) , $ slen ) ; $ matched += $ mlen + $ lendif ; $ i ++ ; } return $ str ; } else { foreach ( array_keys ( $ search ) as $ k ) { if ( is_array ( $ replace ) ) { if ( array_key_exists ( $ k , $ replace ) ) { $ str = AnHelperString :: str_ireplace ( $ search [ $ k ] , $ replace [ $ k ] , $ str , $ count ) ; } else { $ str = AnHelperString :: str_ireplace ( $ search [ $ k ] , '' , $ str , $ count ) ; } } else { $ str = AnHelperString :: str_ireplace ( $ search [ $ k ] , $ replace , $ str , $ count ) ; } } return $ str ; } }
UTF-8 aware alternative to str_ireplace

Case-insensitive version of str_replace

@param string string to search
@param string existing string to replace
@param string new string to replace with
@param int optional count value to be passed by referene
@see http://www.php.net/str_ireplace
UTF - 8 aware alternative to str_ireplace