Merge branch 'maint/7.0'
[ninja.git] / system / core / utf8 / substr_replace.php
blob45e2d2a34b5d49bb0e0e07abee27d7b55341cecb
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * utf8::substr_replace
5 * @package Core
6 * @author Kohana Team
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 _substr_replace($str, $replacement, $offset, $length = NULL)
13 if (utf8::is_ascii($str))
14 return ($length === NULL) ? substr_replace($str, $replacement, $offset) : substr_replace($str, $replacement, $offset, $length);
16 $length = ($length === NULL) ? utf8::strlen($str) : (int) $length;
17 preg_match_all('/./us', $str, $str_array);
18 preg_match_all('/./us', $replacement, $replacement_array);
20 array_splice($str_array[0], $offset, $length, $replacement_array[0]);
21 return implode('', $str_array[0]);