PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/system/utf8/substr_replace.php

https://bitbucket.org/seyar/parshin.local
PHP | 22 lines | 11 code | 2 blank | 9 comment | 1 complexity | cae8c103d09c0418fe0ec49dec569012 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2. /**
  3. * UTF8::substr_replace
  4. *
  5. * @package Kohana
  6. * @author Kohana Team
  7. * @copyright (c) 2007-2010 Kohana Team
  8. * @copyright (c) 2005 Harry Fuecks
  9. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
  10. */
  11. function _substr_replace($str, $replacement, $offset, $length = NULL)
  12. {
  13. if (UTF8::is_ascii($str))
  14. return ($length === NULL) ? substr_replace($str, $replacement, $offset) : substr_replace($str, $replacement, $offset, $length);
  15. $length = ($length === NULL) ? UTF8::strlen($str) : (int) $length;
  16. preg_match_all('/./us', $str, $str_array);
  17. preg_match_all('/./us', $replacement, $replacement_array);
  18. array_splice($str_array[0], $offset, $length, $replacement_array[0]);
  19. return implode('', $str_array[0]);
  20. }