PHP substr() function wrapper

@param string $sStr    value to truncate
@param int    $iStart  start position
@param int    $iLength length

@return string
172779
public function substr($sStr, $iStart, $iLength = null)
    {
        if (is_null($iLength)) {
            return substr($sStr, $iStart);
        }
        return substr($sStr, $iStart, $iLength);
    }
1079621
private function mbStrPad($str, $pad_len, $pad_str = ' ', $dir = STR_PAD_RIGHT, $encoding = NULL)
    {
        $encoding = $encoding === NULL ? mb_internal_encoding() : $encoding;
        $padBefore = $dir === STR_PAD_BOTH || $dir === STR_PAD_LEFT;
        $padAfter = $dir === STR_PAD_BOTH || $dir === STR_PAD_RIGHT;
        $pad_len -= mb_strlen($str, $encoding);
        $targetLen = $padBefore && $padAfter ? $pad_len / 2 : $pad_len;
        $strToRepeatLen = mb_strlen($pad_str, $encoding);
        $repeatTimes = ceil($targetLen / $strToRepeatLen);
        $repeatedString = str_repeat($pad_str, max(0, $repeatTimes)); // safe if used with valid utf-8 strings
        $before = $padBefore ? mb_substr($repeatedString, 0, floor($targetLen), $encoding) : '';
        $after = $padAfter ? mb_substr($repeatedString, 0, ceil($targetLen), $encoding) : '';
        return $before . $str . $after;
    }
1183687
static function strdiff($str1, $str2)
    {
        if(strlen($str1) < strlen($str2)) {
            $strtmp = $str1;
            $str1 = $str2;
            $str2 = $strtmp;
        }

        $start = stripos($str1, $str2);

        $result_str = substr($str1, $start + strlen($str2));

        return $result_str ? $result_str : '';
    }
1164165
@Nullable
  public static String stripBidi (@Nullable final String sStr)
  {
    if (sStr == null || sStr.length () <= 1)
      return sStr;

    String ret = sStr;
    if (isBidi (ret.charAt (0)))
      ret = ret.substring (1);
    if (isBidi (ret.charAt (ret.length () - 1)))
      ret = ret.substring (0, ret.length () - 1);
    return ret;
  }
1097681
public static function substr($string, $start, $length = null)
    {
        return mb_substr($string, $start, $length, self::ENCODING);
    }
1001987
public static function cutStr($str, $length=100, $postfix='...')
    {
        if ( strlen($str) < $length)
            return $str;

        $temp = substr($str, 0, $length);
        return substr($temp, 0, strrpos($temp, ' ') ) . $postfix;
    }
105192
public static function substr($string, $start = 0, $length, $dot = null)
    {
        $string = self::byteSubstr($string, $start, $length);
        return $dot ? $string . $dot : $string;
    }
1283196
protected static function prepStr($str, $countSymb = 255)
    {
        //$str = str_replace(['-', '_'], ['', ''], $str);
        $len = strlen($str);
        $len = $len > $countSymb ? $countSymb : $len;
        return substr($str, 0, $len);
    }
704162
async def substr(self, name, start, end=-1):
        
        return await self.execute_command('SUBSTR', name, start, end)
466409
public function substr($start, $length = null, $encoding = null)
    {
        if (!$this->hasMbstring()) {
            return $this->transform('\substr', $start, $length);
        }

        $encoding = $this->encoding($encoding);

        // workaround for php < 5.4.8
        if (is_null($length)) {
            $length = \mb_strlen($this->string, $encoding);
        }

        return $this->transform('\mb_substr', $start, $length, $encoding);
    }
31113
public function sscan($str_key, &$i_iterator, $str_pattern = null, $i_count = null)
    {
        return $this->xxxScan('sscan', $str_key, $i_iterator, $str_pattern, $i_count);
    }
910358
public static function substr(string $string, int $start, int $length = null): string
    {
        return \mb_substr($string, $start, $length, '8bit');
    }
1260603
public final T substr(int beginIndex) {
        if (beginIndex < 0) {
            throw new StringIndexOutOfBoundsException(beginIndex);
        }
        return (beginIndex == 0) ? me() : substr(beginIndex, size());
    }
1065760
private function substring($str, $from = 0, $to = FALSE)
    {
        if ($to !== FALSE) {
            if ($from == $to || ($from <= 0 && $to < 0)) {
                return '';
            }

            if ($from > $to) {
                $from_copy = $from;
                $from = $to;
                $to = $from_copy;
            }
        }

        if ($from < 0) {
            $from = 0;
        }

        $substring = ($to === FALSE) ? substr($str, $from) : substr($str, $from, $to - $from);
        return ($substring === FALSE) ? '' : $substring;
    }
863974
public static function ensureRight(string $str, string $substring): string
    {
        return (string)BaseStringy::create($str)->ensureRight($substring);
    }
1158411
public static function substring($string, $length = 50, $start = 0, $ellipsis = true)
    {
        $newString = trim(mb_substr($string, $start, $length, 'UTF-8'));
        if (mb_strlen($newString) < mb_strlen($string) && $ellipsis) {
            return $newString.'...';
        } //&hellip;

        return $newString;
    }
1172437
public function ucfirst($sSubject)
    {
        $sString = $this->strtoupper($this->substr($sSubject, 0, 1));

        return $sString . $this->substr($sSubject, 1);
    }