substr_replace.php 766 B

1234567891011121314151617181920212223
  1. <?php
  2. /**
  3. * UTF8::substr_replace
  4. *
  5. * @package KO7
  6. *
  7. * @copyright (c) 2007-2016 Kohana Team
  8. * @copyright (c) since 2016 Koseven Team
  9. * @copyright (c) 2005 Harry Fuecks
  10. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
  11. */
  12. function _substr_replace($str, $replacement, $offset, $length = NULL)
  13. {
  14. if (UTF8::is_ascii($str))
  15. 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);
  19. array_splice($str_array[0], $offset, $length, $replacement_array[0]);
  20. return implode('', $str_array[0]);
  21. }