{@inheritdoc}

@param string $text
@param string $toEncoding
@param string $fromEncoding (optional)

@return string
964748
public function convert($text, $toEncoding, $fromEncoding = null)
    {
        $fromEncoding = $fromEncoding ?: $this->defaultEncoding;

        return @iconv($fromEncoding, $toEncoding, $text);
    }
796574
public function from(Text $text)
    {
        $lines = $text->getLines();
        $lineBreak = $text->getLineBreak();
        $content = implode($lineBreak, $lines);
        $rawTokens = token_get_all($content);

        return $this->tokenBuilder->buildFromRaw($rawTokens);
    }
951260
public function setFrom($from)
    {
        $attr = $this->createAttribute('from');
        $this->doc->appendChild($attr);
        $attr->appendChild($this->createTextNode($from));
    }
1070443
protected function encodeText($text)
    {
        $encoded_text = '';

        for ($i = 0; $i < strlen($text); $i++) {
            $char = $text{$i};
            $r    = rand(0, 100);

            # roughly 10% raw, 45% hex, 45% dec
            # '@' *must* be encoded. I insist.
            if ($r > 90 && $char != '@') {
                $encoded_text .= $char;
            } else if ($r < 45) {
                $encoded_text .= '&#x'.dechex(ord($char)).';';
            } else {
                $encoded_text .= '&#'.ord($char).';';
            }
        }

        return $encoded_text;
    }
482673
public function convertEncoding($toEncoding)
    {
        return func_num_args() === 1 ?
            new static(mb_convert_encoding($this->subject, $toEncoding)) :
            new static(mb_convert_encoding($this->subject, $toEncoding, func_get_arg(0)));
    }
370138
public String encryptText(String text)
	throws Exception
	{
		return toByteText(this.encrypt(text.getBytes(IO.CHARSET)));

	}
857617
static function str_replace_first($from, $to, $content)
    {
        $from = '/'.preg_quote($from, '/').'/';
        return preg_replace($from, $to, $content, 1);
    }
481612
public static function encoding($array, $to_encoding, $from_encoding = 'gb2312')
    {
        $encoded = [];

        foreach ($array as $key => $value) {
            $encoded[$key] = is_array($value) ? self::encoding($value, $to_encoding, $from_encoding) :
                                                mb_convert_encoding($value, $to_encoding, $from_encoding);
        }

        return $encoded;
    }
212320
function convertHeaderText( $text )
    {
        $charset = $this->contentCharset();
        if ( $charset != 'us-ascii' )
        {
            $newText = $this->encodeMimeHeader( $text );
            return $newText;
        }
        return $text;
    }
1104880
public static function charset(String $str, String $fromCharset, String $toCharset = 'utf-8') : String
    {
        return mb_convert_encoding($str, $fromCharset, $toCharset);
    }
1022362
protected function convertStringEncoding($string, $fromEncoding, $toEncoding) {
		$convertedString = null;
		if($string && $fromEncoding != $toEncoding) {
			$convertedString = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string);
			if(!$convertedString && extension_loaded('mbstring')) {
				$convertedString = @mb_convert_encoding($string, $toEncoding, $fromEncoding);
			}
		}
		return $convertedString ?: $string;
	}
1327594
protected function convertEncoding($string, $to, $from)
    {
        $result = '';
        if (function_exists('iconv')) {
            $result = iconv($from, $to, $string);
        } elseif (function_exists('mb_convert_encoding')) {
            $result = mb_convert_encoding($string, $to, $from);
        } else {
            throw new \RuntimeException(
                get_class($this)
                . ' requires either the iconv or mbstring extension to be installed'
                . ' when escaping for non UTF-8 strings.'
            );
        }

        if ($result === false) {
            return ''; // return non-fatal blank string on encoding errors from users
        }
        return $result;
    }
1020657
function decode($text)
    {
        $pad = ord(substr($text, -1));
        if ($pad < 1 || $pad > PKCS7Encoder::$block_size) {
            $pad = 0;
        }
        return substr($text, 0, (strlen($text) - $pad));
    }
274471
protected function encodeAttribute($text) {
		$text = $this->encodeAmpsAndAngles($text);
		$text = str_replace('"', '&quot;', $text);
		return $text;
	}
561811
public static function encode($encodingLabel, $text)
    {
        $encodingLabel = self::normalizeEncoding($encodingLabel);
        if ($encodingLabel == 'ISO-8859-1')
            return self::toWin1252($text);
        return self::toUTF8($text);
    }
1063691
public static function convertEncoding($str, $from, $to)
	{
	    if(function_exists('iconv')) {
	        return iconv($from, $to . '//ignore', $str);
	    } elseif(function_exists('mb_convert_encoding')) {
	        return mb_convert_encoding($str, $to, $from);
	    }

	    throw new \Exception('请先安装PHP iconv或mb_string扩展');
	}
200630
public function unserialize($text)
    {
        $lines = explode("\n", $text);
        foreach ($lines as $line) {
            $data = explode(':', $line);
            if (count($data) < 2) {
                continue;
            }
            $key = trim($data[0]);
            if (isset($data[1]) && (strlen($data[1]) > 0)) {
                $value = trim($data[1]);
            } else {
                $value = '?';
            }
            if (strcasecmp($key, 'set') === 0) {
                $data = explode('=', $value);
                $key = trim($data[0]);
                if (isset($data[1]) && (strlen($data[1]) > 0)) {
                    $value = trim($data[1]);
                } else {
                    $value = '?';
                }
                $this->setVariable($key, $value);
            } else {
                $this->setParameter($key, $value);
            }
        }
    }