1 <?php defined('SYSPATH') OR die('No direct access allowed.');
7 * @copyright (c) 2007 Kohana Team
8 * @copyright (c) 2005 Harry Fuecks
9 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
11 function _str_ireplace($search, $replace, $str, & $count = NULL)
13 if (utf8::is_ascii($search) AND utf8::is_ascii($replace) AND utf8::is_ascii($str))
14 return str_ireplace($search, $replace, $str, $count);
18 foreach ($str as $key => $val)
20 $str[$key] = utf8::str_ireplace($search, $replace, $val, $count);
25 if (is_array($search))
27 $keys = array_keys($search);
31 if (is_array($replace))
33 if (array_key_exists($k, $replace))
35 $str = utf8::str_ireplace($search[$k], $replace[$k], $str, $count);
39 $str = utf8::str_ireplace($search[$k], '', $str, $count);
44 $str = utf8::str_ireplace($search[$k], $replace, $str, $count);
50 $search = utf8::strtolower($search);
51 $str_lower = utf8::strtolower($str);
53 $total_matched_strlen = 0;
56 while (preg_match('/(.*?)'.preg_quote($search, '/').'/s', $str_lower, $matches))
58 $matched_strlen = strlen($matches[0]);
59 $str_lower = substr($str_lower, $matched_strlen);
61 $offset = $total_matched_strlen + strlen($matches[1]) + ($i * (strlen($replace) - 1));
62 $str = substr_replace($str, $replace, $offset, strlen($search));
64 $total_matched_strlen += $matched_strlen;