str_split.php 620 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. /**
  3. * UTF8::str_split
  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 _str_split($str, $split_length = 1)
  13. {
  14. $split_length = (int) $split_length;
  15. if (UTF8::is_ascii($str))
  16. return str_split($str, $split_length);
  17. if ($split_length < 1)
  18. return FALSE;
  19. if (UTF8::strlen($str) <= $split_length)
  20. return [$str];
  21. preg_match_all('/.{'.$split_length.'}|[^\x00]{1,'.$split_length.'}$/us', $str, $matches);
  22. return $matches[0];
  23. }