Encode a string into base58.

@param  string $string The string you wish to encode.
@since Release v1.1.0
@return string The Base58 encoded string.
978627
public function encode($string)
    {
        // Type validation
        if (is_string($string) === false) {
            throw new InvalidArgumentException('Argument $string must be a string.');
        }

        // If the string is empty, then the encoded string is obviously empty
        if (strlen($string) === 0) {
            return '';
        }

        // Strings in PHP are essentially 8-bit byte arrays
        // so lets convert the string into a PHP array
        $bytes = array_values(unpack('C*', $string));

        // Now we need to convert the byte array into an arbitrary-precision decimal
        // We basically do this by performing a base256 to base10 conversion
        $decimal = $bytes[0];

        for ($i = 1, $l = count($bytes); $i < $l; $i++) {
            $decimal = bcmul($decimal, 256);
            $decimal = bcadd($decimal, $bytes[$i]);
        }

        // This loop now performs base 10 to base 58 conversion
        // The remainder or modulo on each loop becomes a base 58 character
        $output = '';
        while ($decimal >= $this->base) {
            $div = bcdiv($decimal, $this->base, 0);
            $mod = bcmod($decimal, $this->base);
            $output .= $this->alphabet[$mod];
            $decimal = $div;
        }

        // If there's still a remainder, append it
        if ($decimal > 0) {
            $output .= $this->alphabet[$decimal];
        }

        // Now we need to reverse the encoded data
        $output = strrev($output);

        // Now we need to add leading zeros
        foreach ($bytes as $byte) {
            if ($byte === 0) {
                $output = $this->alphabet[0] . $output;
                continue;
            }
            break;
        }

        return (string) $output;
    }
974633
public static function decode($string)
    {
        $xml = simplexml_load_string($string);
        $array = array($xml->getName() => (array) $xml);
        $array = self::loopDecode($array);

        return $array;
    }
31136
public function encrypt($string)
  {
    $string = trim($string);
    $encryp = "";
    $length = strlen($string);
    $string .= str_repeat(chr(0), (8-($length%8))%8);

    for($i = 0; $i < $length; $i += 8)
    {
      list(,$xl,$xr) = unpack("N2", substr($string, $i, 8));
      $this->encipher($xl, $xr);
      $encryp .= pack("N2", $xl, $xr);
    }

    return base64_encode($encryp);
  }
1298001
public static function strlenForGbk($string)
	{
		$l = strlen($string);
		$p = $c = 0;
		while ($p < $l)
		{
			if ($string[$p] > "\x80")
				$p += 2;
			else
				$p++;
			$c++;
		}
		return $c;
	}
33874
public static function strlenForUtf8($string)
	{
		$l = strlen($string);
		$p = $c = 0;
		while ($p < $l)
		{
			$a = $string[$p];
			if ($a < "\xC0")
				$p++;
			elseif ($a < "\xE0")
				$p += 2;
			elseif ($a < "\xF0")
				$p += 3;
			elseif ($a < "\xF8")
				$p += 4;
			elseif ($a < "\xFC")
				$p += 5;
			else
				$p += 6;
			$c++;
		}
		return $c;
	}
921019
protected function encodeString($string)
    {
        // If no encoding value was passed in...
        if ($this->encoding === null) {
            return $string;
        }

        $detect = mb_detect_encoding($string);

        // If the current encoding is already the requested encoding
        if (is_string($detect) && $detect === $this->encoding) {
            return $string;
        }

        // Failed to determine encoding
        if (is_bool($detect)) {
            return $string;
        }

        // Convert it!
        return mb_convert_encoding($string, $this->encoding, $detect);
    }
402142
public static function encodeMb4(string $string): string
    {
        // Does this string have any 4+ byte Unicode chars?
        if (max(array_map('ord', str_split($string))) >= 240) {
            $string = preg_replace_callback('/./u', function (array $match) {
                if (strlen($match[0]) >= 4) {
                    // (Logic pulled from WP's wp_encode_emoji() function)
                    // UTF-32's hex encoding is the same as HTML's hex encoding.
                    // So, by converting from UTF-8 to UTF-32, we magically
                    // get the correct hex encoding.
                    $unpacked = unpack('H*', mb_convert_encoding($match[0], 'UTF-32', 'UTF-8'));

                    return isset($unpacked[1]) ? '&#x' . ltrim($unpacked[1], '0') . ';' : '';
                }

                return $match[0];
            }, $string);
        }

        return $string;
    }
228958
public function convertToUTF8Ansii($string){
			if (is_array($string)) {
				foreach ($string as $k => $v) {
					$string[$k] = $this->convertToUTF8Ansii($v);
				}
			} else if (is_string ($string)) {
				return mb_convert_encoding($string, "UTF-8", "Windows-1252");
			}
			return $string;
		}
432502
private function convertToUTF8($string)
    {
        $encoding = mb_detect_encoding($string, mb_detect_order(), false);

        if ($encoding == "UTF-8") {
            $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8');
        }

        $out = iconv(mb_detect_encoding($string, mb_detect_order(), false), "UTF-8//IGNORE", $string);
        return $out;
    }
1007223
public static function encode(String $string) : String
    {
        $secBadChars = self::$scriptBadChars;

        if( ! empty($secBadChars) )
        {
            foreach( $secBadChars as $badChar => $changeChar )
            {
                if( is_numeric($badChar) )
                {
                    $badChar = $changeChar;
                    $changeChar = '';
                }

                $badChar = trim($badChar, '/');

                $string = preg_replace('/'.$badChar.'/xi', $changeChar, $string);
            }
        }

        return $string;
    }
985959
protected static function base58_decode($base58)
    {
        $origbase58 = $base58;
        $return = "0";
        for ($i = 0; $i < strlen($base58); $i++) {
            $return = gmp_add(gmp_mul($return, 58), strpos(self::$B58_DIGITS, $base58[$i]));
        }
        $return = gmp_strval($return, 16);
        for ($i = 0; $i < strlen($origbase58) && $origbase58[$i] == "1"; $i++) {
            $return = "00" . $return;
        }
        if (strlen($return) % 2 != 0) {
            $return = "0" . $return;
        }
        return $return;
    }
607476
public static function encodeUtf8ToFileSystem($string){
		if (preg_match('//u', $string) && strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') {
			return iconv('utf-8', 'cp1252//IGNORE' ,  $string);
		}
		return $string;
	}
476638
private static function toUtf8($string) {

        if(static :: getEncoding() === 'utf-8') {
            $result = $string;
        }
        else {
            $result = static :: convert($string, static :: getEncoding(), 'UTF-8');
        }

        if(false === static :: isUtf8($result)) {
            return trigger_error(sprintf('String to be escaped was not valid UTF-8 or could not be converted'), E_USER_ERROR);
        }

        return $result;
    }
1116948
public static function is_base64(string $string) : bool
  {
    if (base64_encode(base64_decode($string, true)) === $string) return true;
    return false;
  }
1046621
public static function safeBase64Decode($string)
    {
        $data = str_replace(array('-', '_'), array('+', '/'), $string);
        $mod4 = strlen($data) % 4;
        if ($mod4) {
            $data .= substr('====', $mod4);
        }

        return static::base64Decode($data);
    }
176502
public static function fromString($string)
    {
        $matches = array();
        $valid = \preg_match(
            '#^([-,\+])?([0-9]*[\.\/]?[0-9]*)([-,\+]){1}([0-9]*[\.\/]?[0-9]*)i$#',
            \trim($string),
            $matches
        );

        if ($valid !== 1) {
            throw new \InvalidArgumentException(
                'The string representation of the complex number is invalid.'
            );
        }

        $real = $matches[2];
        $imaginary = $matches[4];

        if ($matches[1] && $matches[1] == '-') {
            $real = '-' . $real;
        }
        if ($matches[3] && $matches[3] == '-') {
            $imaginary = '-' . $imaginary;
        }
        
        return self::create(self::convertType($real), self::convertType($imaginary));
    }
430372
protected function normalizeString($string)
    {
        if (false === strpos($string, '_')) {
            return $string;
        }

        $offset = strspn($string, '_');
        if ($offset) {
            $underscorePrefix = substr($string, 0, $offset);
            $string = substr($string, $offset);
        } else {
            $underscorePrefix = '';
        }

        return $underscorePrefix.parent::normalizeString($string);
    }