1 <?php
2 3 4
5
6
7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 function utf8_ireplace($search, $replace, $str, $count = NULL){
22
23 if ( !is_array($search) ) {
24
25 $slen = strlen($search);
26 if ( $slen == 0 ) {
27 return $str;
28 }
29
30 $lendif = strlen($replace) - strlen($search);
31 $search = utf8_strtolower($search);
32
33 $search = preg_quote($search, '/');
34 $lstr = utf8_strtolower($str);
35 $i = 0;
36 $matched = 0;
37 while ( preg_match('/(.*)'.$search.'/Us',$lstr, $matches) ) {
38 if ( $i === $count ) {
39 break;
40 }
41 $mlen = strlen($matches[0]);
42 $lstr = substr($lstr, $mlen);
43 $str = substr_replace($str, $replace, $matched+strlen($matches[1]), $slen);
44 $matched += $mlen + $lendif;
45 $i++;
46 }
47 return $str;
48
49 } else {
50
51 foreach ( array_keys($search) as $k ) {
52
53 if ( is_array($replace) ) {
54
55 if ( array_key_exists($k,$replace) ) {
56
57 $str = utf8_ireplace($search[$k], $replace[$k], $str, $count);
58
59 } else {
60
61 $str = utf8_ireplace($search[$k], '', $str, $count);
62
63 }
64
65 } else {
66
67 $str = utf8_ireplace($search[$k], $replace, $str, $count);
68
69 }
70 }
71 return $str;
72
73 }
74
75 }
76
77
78