public function base64EncodeWrapMB($str, $linebreak = null)
    {
        $start = '=?' . $this->CharSet . '?B?';
        $end = '?=';
        $encoded = '';
        if ($linebreak === null) {
            $linebreak = $this->LE;
        }

        $mb_length = mb_strlen($str, $this->CharSet);
        // Each line must have length <= 75, including $start and $end
        $length = 75 - strlen($start) - strlen($end);
        // Average multi-byte ratio
        $ratio = $mb_length / strlen($str);
        // Base64 has a 4:3 ratio
        $avgLength = floor($length * $ratio * .75);

        for ($i = 0; $i < $mb_length; $i += $offset) {
            $lookBack = 0;
            do {
                $offset = $avgLength - $lookBack;
                $chunk = mb_substr($str, $i, $offset, $this->CharSet);
                $chunk = base64_encode($chunk);
                $lookBack++;
            } while (strlen($chunk) > $length);
            $encoded .= $chunk . $linebreak;
        }

        // Chomp the last linefeed
        $encoded = substr($encoded, 0, -strlen($linebreak));
        return $encoded;
    }
public function base64EncodeWrapMB($str, $linebreak = null)
    {
        $start = '=?' . $this->CharSet . '?B?';
        $end = '?=';
        $encoded = '';
        if ($linebreak === null) {
            $linebreak = $this->LE;
        }

        $mb_length = mb_strlen($str, $this->CharSet);
        // Each line must have length <= 75, including $start and $end
        $length = 75 - strlen($start) - strlen($end);
        // Average multi-byte ratio
        $ratio = $mb_length / strlen($str);
        // Base64 has a 4:3 ratio
        $avgLength = floor($length * $ratio * .75);

        for ($i = 0; $i < $mb_length; $i += $offset) {
            $lookBack = 0;
            do {
                $offset = $avgLength - $lookBack;
                $chunk = mb_substr($str, $i, $offset, $this->CharSet);
                $chunk = base64_encode($chunk);
                $lookBack++;
            } while (strlen($chunk) > $length);
            $encoded .= $chunk . $linebreak;
        }

        // Chomp the last linefeed
        $encoded = substr($encoded, 0, -strlen($linebreak));
        return $encoded;
    }
public function base64EncodeWrapMB ( $ str , $ linebreak = null ) { $ start = '=?' . $ this -> CharSet . '?B?' ; $ end = '?=' ; $ encoded = '' ; if ( $ linebreak === null ) { $ linebreak = $ this -> LE ; } $ mb_length = mb_strlen ( $ str , $ this -> CharSet ) ; // Each line must have length <= 75, including $start and $end $ length = 75 - strlen ( $ start ) - strlen ( $ end ) ; // Average multi-byte ratio $ ratio = $ mb_length / strlen ( $ str ) ; // Base64 has a 4:3 ratio $ avgLength = floor ( $ length * $ ratio * .75 ) ; for ( $ i = 0 ; $ i < $ mb_length ; $ i += $ offset ) { $ lookBack = 0 ; do { $ offset = $ avgLength - $ lookBack ; $ chunk = mb_substr ( $ str , $ i , $ offset , $ this -> CharSet ) ; $ chunk = base64_encode ( $ chunk ) ; $ lookBack ++ ; } while ( strlen ( $ chunk ) > $ length ) ; $ encoded .= $ chunk . $ linebreak ; } // Chomp the last linefeed $ encoded = substr ( $ encoded , 0 , - strlen ( $ linebreak ) ) ; return $ encoded ; }
Encode and wrap long multibyte strings for mail headers
without breaking lines within a character.
Adapted from a function by paravoid
@link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
@access public
@param string $str multi-byte text to wrap encode
@param string $linebreak string to use as linefeed/end-of-line
@return string
Encode and wrap long multibyte strings for mail headers without breaking lines within a character . Adapted from a function by paravoid