80 public static function encode($string) {
83 throw new Exception(
'Empty string.');
88 $bytes = str_split($string);
89 $length = count( $bytes );
90 for ($i = 0; $i < $length; $i++) {
91 $bits = base_convert(ord($bytes[$i]), 10, 2);
92 $binary .= str_pad($bits, 8,
'0', STR_PAD_LEFT);
95 $map = array_keys(self::$lut);
96 $fivebits = str_split($binary, 5);
97 $length = count( $fivebits );
98 for ($i = 0; $i < $length; $i++) {
99 $dec = base_convert(str_pad($fivebits[$i], 5,
'0'), 2, 10);