public function encode($string)
    {
        $encoded = '';

        if ($string) {
            $binString = '';

            // Build a binary string representation of the input string
            foreach (str_split($string) as $char) {
                $binString .= str_pad(decbin(ord($char)), 8, 0, STR_PAD_LEFT);
            }

            // Encode the data in 5-bit chunks
            foreach (str_split($binString, 5) as $chunk) {
                $chunk = str_pad($chunk, 5, 0, STR_PAD_RIGHT);
                $encoded .= $this->charset[bindec($chunk)];
            }

            // Add padding to the encoded string as required
            if (strlen($encoded) % 8) {
                $encoded .= str_repeat($this->charset[32], 8 - (strlen($encoded) % 8));
            }
        }

        return $encoded;
    }
public function encode($string)
    {
        $encoded = '';

        if ($string) {
            $binString = '';

            // Build a binary string representation of the input string
            foreach (str_split($string) as $char) {
                $binString .= str_pad(decbin(ord($char)), 8, 0, STR_PAD_LEFT);
            }

            // Encode the data in 5-bit chunks
            foreach (str_split($binString, 5) as $chunk) {
                $chunk = str_pad($chunk, 5, 0, STR_PAD_RIGHT);
                $encoded .= $this->charset[bindec($chunk)];
            }

            // Add padding to the encoded string as required
            if (strlen($encoded) % 8) {
                $encoded .= str_repeat($this->charset[32], 8 - (strlen($encoded) % 8));
            }
        }

        return $encoded;
    }
public function encode ( $ string ) { $ encoded = '' ; if ( $ string ) { $ binString = '' ; // Build a binary string representation of the input string foreach ( str_split ( $ string ) as $ char ) { $ binString .= str_pad ( decbin ( ord ( $ char ) ) , 8 , 0 , STR_PAD_LEFT ) ; } // Encode the data in 5-bit chunks foreach ( str_split ( $ binString , 5 ) as $ chunk ) { $ chunk = str_pad ( $ chunk , 5 , 0 , STR_PAD_RIGHT ) ; $ encoded .= $ this -> charset [ bindec ( $ chunk ) ] ; } // Add padding to the encoded string as required if ( strlen ( $ encoded ) % 8 ) { $ encoded .= str_repeat ( $ this -> charset [ 32 ] , 8 - ( strlen ( $ encoded ) % 8 ) ) ; } } return $ encoded ; }
Encode a string of raw bytes.

@param  string $string
@return string
Encode a string of raw bytes .