Get substring.
@param string full string
@param int first index (starting point)
@param int max string length
@return string substring
766015
public static function substring($string = false, $firstIndex = 0, $maxStringLength = false) {

        if ($string) {

            if (!$maxStringLength) {

                $maxStringLength = (self::length($string) - $firstIndex);
            }

            return substr($string, $firstIndex, $maxStringLength);
        }

        return false;
    }
63754
public String substringBetween(String string, String begin, String end) {
		return substringBetween(string, begin, end, false);
	}
330202
public static function substringToWord($text, $maxLength, $suffix = '...')
    {
        $effect = $text;

        $textLength = mb_strlen($text, 'utf-8');
        $suffixLength = mb_strlen($suffix, 'utf-8');

        $maxLength -= $suffixLength;

        if ($textLength > $maxLength) {
            $effect = mb_substr($text, 0, $maxLength, 'utf-8');
            $lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8');

            if (false !== $lastSpacePosition) {
                $effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8');
            }

            $effect .= $suffix;
        }

        return $effect;
    }
377524
private String getString(int offset, int maxLength) {
        int index = offset;
        int lastIndex = index + maxLength;
        while (index < lastIndex && (buffer[index] != 0)) {
            index++;
        }
        return new String(buffer, offset, index - offset, StandardCharsets.ISO_8859_1);
    }
216408
public static function substr(string $str, int $start=0, $length=null) {
		if (\function_exists('mb_substr')) {
			return \mb_substr($str, $start, $length, 'UTF-8');
		}

		return \substr($str, $start, $length);
	}
633166
public static Slice substring(Slice utf8, int codePointStart, int codePointLength)
    {
        checkArgument(codePointStart >= 0, "codePointStart is negative");
        checkArgument(codePointLength >= 0, "codePointLength is negative");

        int indexStart = offsetOfCodePoint(utf8, codePointStart);
        if (indexStart < 0) {
            throw new IllegalArgumentException("UTF-8 does not contain " + codePointStart + " code points");
        }
        if (codePointLength == 0) {
            return Slices.EMPTY_SLICE;
        }
        int indexEnd = offsetOfCodePoint(utf8, indexStart, codePointLength - 1);
        if (indexEnd < 0) {
            throw new IllegalArgumentException("UTF-8 does not contain " + (codePointStart + codePointLength) + " code points");
        }
        indexEnd += lengthOfCodePoint(utf8, indexEnd);
        if (indexEnd > utf8.length()) {
            throw new InvalidUtf8Exception("UTF-8 is not well formed");
        }
        return utf8.slice(indexStart, indexEnd - indexStart);
    }
218637
public function getSubstr($str, $charset, $start, $length = null)
    {
        $mb = $this->getMbCharset($charset);
        if ($mb !== false) {
            return mb_substr($str, $start, $length, $mb);
        }
        $ic = $this->getIconvAlias($charset);
        if ($length === null) {
            $length = iconv_strlen($str, $ic);
        }
        return iconv_substr($str, $start, $length, $ic);
    }
613088
public static function substring($string, $startpos, $endpos = -1)
    {
        $len = strlen($string);
        $endpos = (int) (($endpos === -1) ? $len - 1 : $endpos);
        if ($startpos > $len - 1 || $startpos < 0) {
            trigger_error("substring(), Startindex out of bounds must be 0<n<$len", E_USER_ERROR);
        }
        if ($endpos > $len - 1 || $endpos < $startpos) {
            trigger_error("substring(), Endindex out of bounds must be $startpos<n<" . ($len - 1), E_USER_ERROR);
        }
        if ($startpos === $endpos) {
            return (string) $string{$startpos};
        } else {
            $len = $endpos - $startpos;
        }

        return substr($string, $startpos, $len + 1);
    }
768520
public UTF8String substring(final int start, final int until) {
    if (until <= start || start >= numBytes) {
      return EMPTY_UTF8;
    }

    int i = 0;
    int c = 0;
    while (i < numBytes && c < start) {
      i += numBytesForFirstByte(getByte(i));
      c += 1;
    }

    int j = i;
    while (i < numBytes && c < until) {
      i += numBytesForFirstByte(getByte(i));
      c += 1;
    }

    if (i > j) {
      byte[] bytes = new byte[i - j];
      copyMemory(base, offset + j, bytes, BYTE_ARRAY_OFFSET, i - j);
      return fromBytes(bytes);
    } else {
      return EMPTY_UTF8;
    }
  }
320652
public static String substring(final String str, final int beginIndex) {
        assertStringNotNull(str);
        if (str.length() < beginIndex) {
            String msg = "The length of the string was smaller than the begin index:";
            msg = msg + " str=" + str + ", beginIndex=" + beginIndex;
            throw new StringIndexOutOfBoundsException(msg);
        }
        return str.substring(beginIndex);
    }
1316806
private static function substr($str,$start,$length=null)
    {
        $ar = array();
        preg_match_all("/./u", $str, $ar);

        if($length != null) {
            return join("",array_slice($ar[0],$start,$length));
        } else {
            return join("",array_slice($ar[0],$start));
        }
    }
359892
function _substr($binary_string, $start, $length) {
        if (function_exists('mb_substr')) {
            return mb_substr($binary_string, $start, $length, '8bit');
        }
        return substr($binary_string, $start, $length);
    }
366229
public function substr($str, $offset = 0, $length = null)
    {
        // Due fix of PHP #62759 The third argument returns an empty string if is 0 or null.
        if ($length !== null) {
            return grapheme_substr($str, $offset, $length);
        }

        return grapheme_substr($str, $offset);
    }
562180
public function substr8($string, $start, $length = false)
    {
        if ($length === false) {
            $length = $this->strlen8($string) - $start;
        }
        if ($this->_mb_substr) {
            return mb_substr($string, $start, $length, '8bit');
        }

        return substr($string, $start, $length);
    }
693088
public SubString substring(int start) {
		JcNumber sub = new JcNumber(start, this, OPERATOR.Common.COMMA_SEPARATOR);
		SubString ret = new SubString(null, sub,
				new FunctionInstance(FUNCTION.String.SUBSTRING, 2));
		QueryRecorder.recordInvocationConditional(this, "substring", ret, QueryRecorder.literal(start));
		return ret;
	}
962761
public String substring(int start, int end) {
        char[] buf = new char[end - start];
        getChars(start, end, buf, 0);
        return new String(buf);
    }
846088
public function substring($text, $searchword, $length = 200)
    {
        $textlen = AnHelperString::strlen($text);
        $lsearchword = AnHelperString::strtolower($searchword);
        $wordfound = false;
        $pos = 0;

        while ($wordfound === false && $pos < $textlen) {
            if (($wordpos = @AnHelperString::strpos($text, ' ', $pos + $length)) !== false) {
                $chunk_size = $wordpos - $pos;
            } else {
                $chunk_size = $length;
            }

            $chunk = AnHelperString::substr($text, $pos, $chunk_size);
            $wordfound = AnHelperString::strpos(AnHelperString::strtolower($chunk), $lsearchword);

            if ($wordfound === false) {
                $pos += $chunk_size + 1;
            }
        }//while

        if ($wordfound !== false) {
            return (($pos > 0) ? '...&nbsp;' : '').$chunk.'&nbsp;...';
        } else {
            if (($wordpos = @AnHelperString::strpos($text, ' ', $length)) !== false) {
                return AnHelperString::substr($text, 0, $wordpos).'&nbsp;...';
            } else {
                return AnHelperString::substr($text, 0, $length);
            }
        }
    }