PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/phpseclib/PHP/Compat/Function/str_split.php

https://bitbucket.org/sunil_nextbits/magento2
PHP | 59 lines | 36 code | 6 blank | 17 comment | 6 complexity | 889ab2b0d90b0962ded2ee65f1bfbc37 MD5 | raw file
  1. <?php
  2. /**
  3. * Replace str_split()
  4. *
  5. * @category PHP
  6. * @package PHP_Compat
  7. * @license LGPL - http://www.gnu.org/licenses/lgpl.html
  8. * @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
  9. * @link http://php.net/function.str_split
  10. * @author Aidan Lister <aidan@php.net>
  11. * @version $Revision: 1.1 $
  12. * @since PHP 5
  13. * @require PHP 4.0.0 (user_error)
  14. */
  15. function php_compat_str_split($string, $split_length = 1)
  16. {
  17. if (!is_scalar($split_length)) {
  18. user_error('str_split() expects parameter 2 to be long, ' .
  19. gettype($split_length) . ' given', E_USER_WARNING);
  20. return false;
  21. }
  22. $split_length = (int) $split_length;
  23. if ($split_length < 1) {
  24. user_error('str_split() The length of each segment must be greater than zero', E_USER_WARNING);
  25. return false;
  26. }
  27. // Select split method
  28. if ($split_length < 65536) {
  29. // Faster, but only works for less than 2^16
  30. preg_match_all('/.{1,' . $split_length . '}/s', $string, $matches);
  31. return $matches[0];
  32. } else {
  33. // Required due to preg limitations
  34. $arr = array();
  35. $idx = 0;
  36. $pos = 0;
  37. $len = strlen($string);
  38. while ($len > 0) {
  39. $blk = ($len < $split_length) ? $len : $split_length;
  40. $arr[$idx++] = substr($string, $pos, $blk);
  41. $pos += $blk;
  42. $len -= $blk;
  43. }
  44. return $arr;
  45. }
  46. }
  47. // Define
  48. if (!function_exists('str_split')) {
  49. function str_split($string, $split_length = 1)
  50. {
  51. return php_compat_str_split($string, $split_length);
  52. }
  53. }