pad

@param string      $string
@param int         $length
@param string      $substring
@param string|null $encoding

@return  string
11395
public static function pad(
        $string,
        $length = 0,
        $substring = ' ',
        $encoding = null
    ) {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;
        $strLength = Mbstring::strlen($string, $encoding);
        $padding = $length - $strLength;

        return static::doPad($string, (int) floor($padding / 2), (int) ceil($padding / 2), $substring, $encoding);
    }
33121
public static function Substring ($string, $start, $length = null, $encoding = Encoding::DEFAULT_ENCODING) {
		if ($length === null) {
			$length = self::Length($string) - $start;
		}
		return mb_substr($string, $start, $length, $encoding);
	}
1228759
public UTF8String rpad(int len, UTF8String pad) {
    int spaces = len - this.numChars(); // number of char need to pad
    if (spaces <= 0 || pad.numBytes() == 0) {
      // no padding at all, return the substring of the current string
      return substring(0, len);
    } else {
      int padChars = pad.numChars();
      int count = spaces / padChars; // how many padding string needed
      // the partial string of the padding
      UTF8String remain = pad.substring(0, spaces - padChars * count);

      byte[] data = new byte[this.numBytes + pad.numBytes * count + remain.numBytes];
      copyMemory(this.base, this.offset, data, BYTE_ARRAY_OFFSET, this.numBytes);
      int offset = this.numBytes;
      int idx = 0;
      while (idx < count) {
        copyMemory(pad.base, pad.offset, data, BYTE_ARRAY_OFFSET + offset, pad.numBytes);
        ++ idx;
        offset += pad.numBytes;
      }
      copyMemory(remain.base, remain.offset, data, BYTE_ARRAY_OFFSET + offset, remain.numBytes);

      return UTF8String.fromBytes(data);
    }
  }
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);
    }
927863
public static function extract($string, $offset, $length = null) {
        if ($length) {
            return mb_substr($string, $offset, $length);
        }

        return mb_substr($string, $offset);
    }
953573
public function fwrite($string, $length = null)
    {
        return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length));
    }
1351614
private function pad($string, $block = 32)
    {
        $pad = $block - (strlen($string) % $block);

        return $string . str_repeat(chr($pad), $pad);
    }
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);
    }
1353705
public function getStringPositionSql($substring, $string)
	{
		$this->connect();

		$query = "SELECT POSITION( $substring IN $string )";
		$this->setQuery($query);
		$position = $this->loadRow();

		return $position['position'];
	}
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);
    }
274837
public function substr($str, $offset = 0, $length = null)
    {
        return iconv_substr($str, $offset, $length, $this->getEncoding());
    }
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;
    }
910358
public static function substr(string $string, int $start, int $length = null): string
    {
        return \mb_substr($string, $start, $length, '8bit');
    }
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);
    }
380683
public function substr($start, $length = null)
    {
        $str = mb_substr($this->value, $start, $length);

        return static::make($str);
    }
105192
public static function substr($string, $start = 0, $length, $dot = null)
    {
        $string = self::byteSubstr($string, $start, $length);
        return $dot ? $string . $dot : $string;
    }
416929
public static function pad($input, $length = 0)
    {
        $input = ltrim($input, '0');

        if ($input == '') {
            $input = '0';
        }

        return str_pad($input, $length, '0', STR_PAD_LEFT);
    }