Encode string to q encoding.

@link   http://tools.ietf.org/html/rfc2047
@param string $str      the text to encode
@param string $position Where the text is going to be used, see the RFC for what that means
@access public
@return string
979830
public function EncodeQ($str, $position = 'text')
    {
        // There should not be any EOL in the string
        $encoded = preg_replace('/[\r\n]*/', '', $str);

        switch (strtolower($position)) {
            case 'phrase':
                $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
                break;
            case 'comment':
                $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
            case 'text':
            default:
                // Replace every high ascii, control =, ? and _ characters
                //TODO using /e (equivalent to eval()) is probably not a good idea
                $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
                    "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);
                break;
        }

        // Replace every spaces to _ (more readable than =20)
        $encoded = str_replace(' ', '_', $encoded);

        return $encoded;
    }
773332
public static function decode(String $str) : String
    {
        return str_replace(array_values(self::$phpTagChars), array_keys(self::$phpTagChars), $str);
    }
801842
public function insert( $position, $string )
	{
		if( $position<= $this->count() && $position >=0 )
		{
			if( $position < $this->pointer )
				$this->pointer = $this->pointer + strlen( $string );
			$left	= substr( $this->toString(), 0, $position );
			$right	= substr( $this->toString(), $position );
			$this->buffer = $left.$string.$right;
		}
		return $this->toString();
	}
923184
private static function _encodeQuotedPrintable($str)
    {
        $str = str_replace('=', '=3D', $str);
        $str = str_replace(self::$qpKeys, self::$qpReplaceValues, $str);
        $str = rtrim($str);
        return $str;
    }
193304
static function dn_decode($str)
    {
        $str = str_pad(strtr($str, '-_', '+/'), strlen($str) % 4, '=', STR_PAD_RIGHT);
        return base64_decode($str);
    }
684305
public static function altEncrypt($str, $pass = '')
    {
        /**
         * if empty values return null
         */
        if (!$str) {
            return null;
        }

        /**
         * ------------------------------------
         * Safe Sanitized hash
         * ------------------------------------
         */
        (is_null($pass) || $pass === false) && $pass = '';
        // safe is use array or object as hash
        $pass = Util::maybeSerialize($pass);
        if (!$pass) {
            $pass = sha1($pass);
        }

        // make an array values -> use key acb
        $str = serialize(array('acb' => $str));
        // rotate 13
        $str = pack('a*', Util::rotate($str.sha1(sha256::hash($pass)), 13));

        /**
         * Doing safe encode base 64
         */
        $str = Util::safeBase64Encode($str);

        /**
         * ------------------------------------
         * Doing convert string
         * ------------------------------------
         */
        $str_arr  = str_split($str);
        $add = 0;
        $div = strlen($str) / strlen($pass);
        $new_pass = '';
        while ($add <= $div) {
            $new_pass .= $pass;
            $add++;
        }
        $pass_arr = str_split($new_pass);
        $ascii = '';
        foreach ($str_arr as $key => $asc) {
            $pass_int = ord($pass_arr[$key]);
            $str_int = ord($asc);
            $int_add = $str_int + $pass_int;
            $ascii .= chr(($int_add+strlen($str)));
        }
        $ascii = trim(Util::safeBase64Encode($ascii));

        /**
         * ------------------------------------
         * Inject Result of with sign
         * ------------------------------------
         */
        if (strlen($ascii) > 10) {
            return substr_replace($ascii, '_aCb=', 10, 0);
        } else {
            return substr_replace($ascii, '_aCb=', 2, 0);
        }
    }
256085
public static function encodeQuotedPrintable($str,
        $lineLength = self::LINELENGTH,
        $lineEnd = self::LINEEND)
    {
        $out = '';
        $str = self::_encodeQuotedPrintable($str);

        // Split encoded text into separate lines
        while ($str) {
            $ptr = strlen($str);
            if ($ptr > $lineLength) {
                $ptr = $lineLength;
            }

            // Ensure we are not splitting across an encoded character
            $pos = strrpos(substr($str, 0, $ptr), '=');
            if ($pos !== false && $pos >= $ptr - 2) {
                $ptr = $pos;
            }

            // Check if there is a space at the end of the line and rewind
            if ($ptr > 0 && $str[$ptr - 1] == ' ') {
                --$ptr;
            }

            // Add string and continue
            $out .= substr($str, 0, $ptr) . '=' . $lineEnd;
            $str = substr($str, $ptr);
        }

        $out = rtrim($out, $lineEnd);
        $out = rtrim($out, '=');
        return $out;
    }
606978
public function getCharAt( $position )
	{
		if($position <= $this->count() && $position >= 0 )
			$character = $this->buffer[$position];
		return $character;
	}
1333308
function encodeToUTF8($str)
    {
        $encodage = mb_detect_encoding($str, "UTF-8, ISO-8859-1, ISO-8859-15, windows-1252", true);
        $str_utf8 = mb_convert_encoding($str, "UTF-8", $encodage);
        return $str_utf8;
    }
581312
public function deleteCharAt( $position )
	{
		$string	= "";
		for( $i = 0; $i < $this->count(); $i++ )
			if( $position != $i )
				$string .= $this->buffer[$i];
		$this->buffer = $string;
		if( $position == $this->pointer )
			$this->pointer++;
		return $this->toString();
	}
131030
public function encodeHex($str)
    {
        if (!ctype_xdigit((string)$str)) {
            return '';
        }

        $numbers = trim(chunk_split($str, 12, ' '));
        $numbers = explode(' ', $numbers);

        foreach ($numbers as $i => $number) {
            $numbers[$i] = hexdec('1' . $number);
        }

        return call_user_func_array([$this, 'encode'], $numbers);
    }
1110372
public static function toAscii(string $str) : string
    {
        $clean = preg_replace('/[^a-zA-Z0-9\.\/_|+ -]/', '', $str);
        $clean = strtolower(trim($clean, '-'));
        $clean = preg_replace('/[\/_|+ -]+/', '-', $clean);

        return $clean;
    }
72984
public static function toString($str){
		$str = strtoupper($str);

		// csSave actually has to be able to consider extra characters
		if(self::$charset === Base32Characters::CROCKFORD){
			$str = str_replace('O', '0', $str);
			$str = str_replace(['I', 'L'], '1', $str);
		}

		return self::bin2str(self::toBin($str));
	}
1287562
public static function encodeOperators(
        $str)
    {
        if (self::$_translations === null) {
            self::_buildTranslations();
        }

        return strtr($str, self::$_translations['encode']);
    }
1325007
function ldap_search_encode($str) {
        $decoded=array("\\","*","(",")",chr(0),"/");
        $encoded=array("\\5c","\\2a","\\28","\\29","\\00","\\2f");
        $str=str_replace($decoded,$encoded,$str);
        return ($str);
    }
1024539
public static function encode(String $str) : String
    {
        return preg_replace
        (
            array_keys(self::$scriptTagChars), 
            array_values(self::$scriptTagChars), 
            $str
        );
    }
799016
public function EncodeString($str, $encoding = 'base64')
    {
        $encoded = '';
        switch (strtolower($encoding)) {
            case 'base64':
                $encoded = chunk_split(base64_encode($str), 76, $this->LE);
                break;
            case '7bit':
            case '8bit':
                $encoded = $this->FixEOL($str);
                //Make sure it ends with a line break
                if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
                    $encoded .= $this->LE;
                }

                break;
            case 'binary':
                $encoded = $str;
                break;
            case 'quoted-printable':
                $encoded = $this->EncodeQP($str);
                break;
            default:
                $this->SetError($this->Lang('encoding') . $encoding);
                break;
        }
        return $encoded;
    }