@param string $string
@param string $encoding

@return string
328719
public static function convertToHtmlEntities($string, $encoding)
    {
        if (function_exists('mb_convert_encoding')) {
            return mb_convert_encoding($string, 'HTML-ENTITIES', $encoding);
        }

        if ('UTF-8' !== $encoding) {
            $string = iconv($encoding, 'UTF-8//IGNORE', $string);
        }

        return preg_replace_callback('/[\x80-\xFF]+/', [__CLASS__, 'htmlEncodingCallback'], $string);
    }
1156677
public static function insert($string, $insert, $position, $encoding = null)
    {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        $length = Mbstring::strlen($string, $encoding);

        if ($position > $length) {
            return $string;
        }

        $left = Mbstring::substr($string, 0, $position, $encoding);
        $right = Mbstring::substr($string, $position, $length, $encoding);

        return $left . $insert . $right;
    }
45105
public static function encode($string)
    {
        return is_null($string) ? self::NULL : strtr($string, self::$encodeMap);
    }
837040
private static function encodeString($string)
    {
        // Note:
        // strlen() returns the number of bytes rather than the number of characters in a string.

        // Differentiate on the string length.
        if (strlen($string) < 32) {
            // fixstr
            $prefix = bindec(101) * 32 + strlen($string);
        } elseif (strlen($string) < pow(2, 8)) {
            // str 8
            $prefix = 0xd9 * 256 + strlen($string);
        } elseif (strlen($string) < pow(2, 16)) {
            // str 16
            $prefix = 0xda * 256 * 256 + strlen($string);
        } elseif (strlen($string) < pow(2, 32)) {
            // str 32
            $prefix = 0xdb * 256 * 256 * 256 * 256 + strlen($string);
        } else {
            throw new UnencodeableException('String to be encoded is too long', 4);
        }

        // Encode it and concatenate with all bytes of the string value.
        return pack('H*', dechex($prefix)) . $string;
    }
976306
public function compile($encoding = 'UTF-8'): string
    {
        $output = '';
        foreach ( $this->compilables as $compilable ) {
            $output .= $compilable->compile($encoding);
        }

        return $output;
    }
116556
public function mbStrLen($string, $encoding = null)
    {
        // Meh, the original mb_strlen interprets a null here as an empty string.
        if ($encoding === null) {
            return mb_strlen($string);
        }
        return mb_strlen($string, $encoding);
    }
848282
protected function _encodeString(&$string)
    {
        // Escape these characters with a backslash or unicode escape:
        // " \ / \n \r \t \b \f
        $search  = array('\\', "\n", "\t", "\r", "\b", "\f", '"', '\'', '&', '<', '>', '/');
        $replace = array('\\\\', '\\n', '\\t', '\\r', '\\b', '\\f', '\\u0022', '\\u0027', '\\u0026',  '\\u003C', '\\u003E', '\\/');
        $string  = str_replace($search, $replace, $string);

        // Escape certain ASCII characters:
        // 0x08 => \b
        // 0x0c => \f
        $string = str_replace(array(chr(0x08), chr(0x0C)), array('\b', '\f'), $string);
        $string = self::encodeUnicodeString($string);

        return '"' . $string . '"';
    }
1271964
public function encoding($encoding = null)
    {
        if (!func_num_args()) {
            return $this->_stream->encoding();
        }
        $this->_stream->encoding($encoding);
        return $this;
    }
11345
public function encodeString(string $string, ?string $charset = 'utf-8', int $firstLineOffset = 0, int $maxLineLength = 0): string
    {
        $lines = [];
        $lineCount = 0;
        $lines[] = '';
        $currentLine = &$lines[$lineCount++];

        if (0 >= $maxLineLength) {
            $maxLineLength = 75;
        }

        $charStream = new CharacterStream($string, $charset);
        $thisLineLength = $maxLineLength - $firstLineOffset;

        while (null !== $char = $charStream->read(4)) {
            $encodedChar = rawurlencode($char);
            if (0 !== \strlen($currentLine) && \strlen($currentLine.$encodedChar) > $thisLineLength) {
                $lines[] = '';
                $currentLine = &$lines[$lineCount++];
                $thisLineLength = $maxLineLength;
            }
            $currentLine .= $encodedChar;
        }

        return implode("\r\n", $lines);
    }
651089
public static function toLowerCase($str, $encoding = null)
    {
        return (string) Stringy::create($str, $encoding)->toLowerCase();
    }
299527
public function decode( string$encoded )
	{
		$data= [];

		foreach( explode( '&', $encoded ) as $value )
		{
			$key= urldecode( strtok( $value, '=' ) );
			$value= urldecode( strtok( '' ) );

			$keys= explode( '[', str_replace( ']', '', $key ) );

			$p= &$data;

			foreach( $keys as $key )
			{
				is_array( $p ) or $p= [];

				$p= &$p[$key];
			}

			$p= $value;

			unset( $p );
		}

		return $data;
	}
74048
public static function removeLeft($string, $search, $encoding = null)
    {
        if ($string === '') {
            return '';
        }

        if ($search === '') {
            return $string;
        }

        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        if (!static::startsWith($string, $search, true, $encoding)) {
            return $string;
        }

        return Mbstring::substr($string, Mbstring::strlen($search), null, $encoding);
    }
578346
public static function getShortPinyin($string, $encoding = 'utf-8')
    {
        if ($string != self::$string || $encoding != self::$encoding) {
            self::chineseToPinyin($string, $encoding);
        }
        return self::$short_pinyin;
    }
311153
public static function filter($string, callable $callback, $encoding = null)
    {
        return static::map(
            $string,
            function ($char, &$key) use ($callback) {
                if ($callback instanceof \Closure) {
                    $result = $callback($char, $key);
                } else {
                    $result = $callback($char);
                }

                return $result ? $char : '';
            },
            $encoding
        );
    }
253252
public static function fromString($str, $encoding = self::ENCODING){
		
		if(!\is_string($str)){
			throw new \InvalidArgumentException('$str must be a PHP string');
		}
		
		if(!\is_string($encoding)){
			throw new \InvalidArgumentException('$encoding must be a string');
		}
		
		return new static($str, $encoding);
		
	}
486882
private static function encodeUTF16($string, $compressed = '')
    {
        if ($compressed) {
            $string = self::uncompressByteString($string);
        }

        return PHPExcel_Shared_String::ConvertEncoding($string, 'UTF-8', 'UTF-16LE');
    }
187727
public static function shuffle($str, $encoding = null)
    {
        return (string) Stringy::create($str, $encoding)->shuffle();
    }