Implementation str_split() function for UTF-8 encoding string.

@param   string|null      $s
@param   int|null|digit   $length
@return  array|bool|null  Returns FALSE if error occurred
514910
public static function str_split($s, $length = null)
	{
		if (! ReflectionTypeHint::isValid()) return false;
		if (is_null($s)) return $s;

		$length = ($length === null) ? 1 : intval($length);
		if ($length < 1) return false;
		#there are limits in regexp for {min,max}!
		if (preg_match_all('~.~suSX', $s, $m) === false) return false;
		if (function_exists('preg_last_error') && preg_last_error() !== PREG_NO_ERROR) return false;
		if ($length === 1) $a = $m[0];
		else
		{
			$a = array();
			for ($i = 0, $c = count($m[0]); $i < $c; $i += $length) $a[] = implode('', array_slice($m[0], $i, $length));
		}
		return $a;
	}
1031479
public function parseEncodedBinary(&$s, &$p)
    {
        $f = ord(mb_orig_substr($s, $p, 1));
        ++$p;

        if ($f <= 250) {
            return $f;
        }

        if ($s === 251) {
            return null;
        }

        if ($s === 255) {
            return false;
        }

        if ($f === 252) {
            $o = $p;
            $p += 2;

            return $this->bytes2int(mb_orig_substr($s, $o, 2));
        }

        if ($f === 253) {
            $o = $p;
            $p += 3;

            return $this->bytes2int(mb_orig_substr($s, $o, 3));
        }

        $o = $p;
        $p = +8;

        return $this->bytes2int(mb_orig_substr($s, $o, 8));
    }
590498
public function substring($start, $length = null){
		
		if(!$this->offsetExists($start)){
			throw new \OutOfRangeException('$start is an invalid index');
		}
		
		if($length !== null && !\is_numeric($length) || $length < 0){
			throw new \InvalidArgumentException('$length is invalid');
		}
		
		return new static(\mb_substr($this->_Value, $start, $length, $this->_Encoding),
				$this->_Encoding);
		
	}
918429
public static function strSplit($string, $length = 1, $encoding = null)
    {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        if ($length === 1) {
            return preg_split("//u", $string, -1, PREG_SPLIT_NO_EMPTY);
        }

        if ($length > 1) {
            $return_value = [];
            $string_length = static::strlen($string, $encoding);

            for ($i = 0; $i < $string_length; $i += $length) {
                $return_value[] = static::substr($string, $i, $length, $encoding);
            }

            return $return_value;
        }

        return false;
    }
1185308
public function split($length)
    {
        $id = new Horde_Stream_Temp();
        $id->add($this->tostring_sort, true);

        $out = array();

        do {
            $out[] = $id->substring(0, $length) . $id->getToChar(',');
        } while (!$id->eof());

        return $out;
    }
394568
public static function randomAlphabetAndDigit($length)
    {
        $charsSpace = self::DIGIT.self::ALPHABET;
        return self::randomByCharsSpace($length, $charsSpace);
    }
263493
public function read($offset, $length = 1)
    {
        $ret = '';
        $segno = floor($offset / $this->segsize);
        $sOffset = $offset % $this->segsize;
        while (true) {
            if (!isset($this->segments[$segno])) {
                if (!$this->open($segno)) {
                    goto ret;
                }
            }

            $ret .= shmop_read($this->segments[$segno], $sOffset, min($length - mb_orig_strlen($ret), $this->segsize));

            if (mb_orig_strlen($ret) >= $length) {
                goto ret;
            }

            ++$segno;

            $sOffset = 0;
        }
        ret:

        return $ret === '' ? false : $ret;
    }
1128964
public static function substr($string, $from, $length = null)
    {
        if (false === $encoding = mb_detect_encoding($string, null, true)) {
            return substr($string, $from, $length);
        }

        return mb_substr($string, $from, $length, $encoding);
    }
1322550
protected function ends($s,$length)
    {
        if ($s[$length-1] != $this->b[$this->k])
            return false;
        if ($length >= $this->k+1)
            return false;
        if (substr_compare($this->b,$s,$this->k-$length+1,$length)!=0)
            return false;

        $this->j = $this->k-$length;

        return true;
    }
610470
public function getSlicePath($offset, $length = null)
    {
        $array = explode('/', $this->getPath());

        if (empty($array[0])) {
            array_shift($array);
        }

        return array_slice($array, $offset, $length);
    }
1314856
static function substring($input, $start, $length = null) {
		return self::substr($input, $start, $length, "utf-8");
	}
1332238
public static function substr($string, $offset, $length = null)
    {
        return mb_substr($string, $offset, $length === null ? mb_strlen($string, static::ENC_UTF8) : $length, static::ENC_UTF8);
    }
192452
public function substr($start, $length = null)
  {
    $string = ($length !== null) ? substr($this->string, $start, $length) : substr($this->string, $start);

    return new self($string);
  }
1078518
static function getRandomString($length = 8)
    {

        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

        $value = '';
        $charsLength = strlen($chars) - 1;

        for ($i = 1 ; $i <= $length; $i++) {
            $value .= $chars[rand(0, $charsLength)];
        }

        return $value;

    }
442941
public function substring($start, $length = NULL) {
        //TODO: Fix to PHP #42101
        if($length === NULL) {
            $newValue = mb_substr($this->string, $start);
        } else {
            $newValue = mb_substr($this->string, $start, $length);
        }

        return $this->createClone($newValue);
    }
606407
static function str_split($string, $split_length = 1) {
    if ($split_length < 1) {
      return FALSE;
    }
    preg_match_all('/.{1,' . $split_length . '}/u', $string, $matches);
    return $matches[0];
  }
47414
public static function getSlice($string, $offset, $length = null)
    {
        if (self::checkMB()) {
            return mb_substr($string, $offset, $length, '8bit');
        }
        if ($length === null) {
            $length = strlen($string);
        }
        return substr($string, $offset, $length);
    }