Alias for mb_substr() function
@param string $string
@param int $start
@param int|null $length
@param string $encode
@return string
335492
public static function sub(string $string, int $start, ?int $length = null, string $encode = 'UTF-8'): ?string
    {
        return mb_substr($string, $start, $length, $encode);
    }
919776
static function Part($string, $start, $length = null)
    {
        self::InitEncoding();
        if ($length !== null)
            return mb_substr($string, $start, $length);

        return mb_substr($string, $start);
    }
177205
public function substring(int $start, int $length = null): self
    {
        if ($this->length() === 0) {
            return $this;
        }

        $sub = \mb_substr($this->value, $start, $length, (string) $this->encoding());

        return new self($sub, $this->encoding);
    }
418409
public function startsWith($substring) {
		$substringLength = mb_strlen($substring, $this->encoding);
		$startOfStr = mb_substr($this->string, 0, $substringLength, $this->encoding);

		return (string) $substring === $startOfStr;
	}
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);
    }
608322
public static function word_substr($text, $from, $minlength, $maxlength) {
        $text = mb_substr($text, $from, $maxlength);
        $p1 = strrpos($text, ' ');
        if ($p1 >= $minlength) {
            return mb_substr($text, 0, $p1);
        }
        return $text;
    }
1060667
public static function substr($str, $len, $start = 0, $encoding = 'UTF-8') {
	    if(function_exists('iconv_substr')) {
	        return iconv_substr($str, $start, $len, $encoding);
	    } elseif(function_exists('mb_substr')) {
	        return mb_substr($str, $start, $len, $encoding);
	    }
	    throw new \Exception('请先安装PHP iconv或mb_string扩展');
	}
1265848
public static function truncate2(string $str, int $start, int $length = null): string
    {
        if (!$length) {
            $length = $start;
            $start  = 0;
        }

        if (\strlen($str) <= $length) {
            return $str;
        }

        if (\function_exists('mb_substr')) {
            $str = \mb_substr(\strip_tags($str), $start, $length, 'utf-8');
        } else {
            $str = \substr($str, $start, $length) . '...';
        }

        return $str;
    }
809358
function substr($str,$start,$len=0) {
		if ($start<0)
			$start=$this->strlen($str)+$start;
		if (!$len)
			$len=$this->strlen($str)-$start;
		return preg_match('/^.{'.$start.'}(.{0,'.$len.'})/us',$str,$match)?
			$match[1]:FALSE;
	}
465264
public static function substr($str, $start, $length, $suffix = false) {
        if (mb_strlen($str, 'utf-8') <= $length) return $str;
        $slice = mb_substr($str, $start, $length, 'utf-8');
		if ($suffix) return $slice."…";
		return $slice;
	}
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);
    }
360804
public function substr($start = 0, $length = null)
    {
        $function = static::$functions[(int) static::$useMbstring]['substr'];

        return new self($function($this->string, $start, $length));
    }
1123328
public static function removeChar($string, $offset, $length = null, $encoding = null)
    {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        if (Mbstring::strlen($string, $encoding) < abs($offset)) {
            return $string;
        }

        $length = $length === null ? 1 : $length;

        return Mbstring::substrReplace($string, '', $offset, $length, $encoding);
    }
231642
public function transform(string $value, int $start = 0, int $length = null): string {
        return $length === null ? substr($value, $start) : substr($value, $start, $length);
    }
1273880
protected static function intersect($string, $subString, $start)
    {
        $cut = str_split(substr($string, $start, strlen($subString)));
        $comp = str_split($subString);
        foreach ($cut as $i => $c) {
            if ($comp[$i] === $c) {
                $intersect[] = $c;
            } else {
                break; // Stop loop since intersection ends.
            }
        }
        if (!empty($intersect)) {
            return implode('', $intersect);
        }

        return '';
    }
561750
public static function mb_substr_replace($original, $replacement, $position, $length)
    {
        $startString = mb_substr($original, 0, $position, "UTF-8");
        $endString = mb_substr($original, $position + $length, mb_strlen($original), "UTF-8");

        return $startString . $replacement . $endString;
    }
961935
static function get_string_between($string, $start, $end){
        try {
            $string = " ".$string;
            $ini = strpos($string,$start);
            if ($ini == 0) return "Start non trouve";
            $ini += strlen($start);
            $len = strpos($string,$end,$ini) - $ini;
            return substr($string,$ini,$len);
        } catch (Exception $e) {
            $msg = $e->getMessage();
            Throw new \Exception('Erreur dans '.__CLASS__.' : '.$msg);
            return null;
        }
    }