PHPMailer\PHPMailer

PHPMailer::base64EncodeWrapMB()publicWP 1.0

Encode and wrap long multibyte strings for mail headers without breaking lines within a character. Adapted from a function by paravoid.

Метод класса: PHPMailer{}

Хуков нет.

Возвращает

Строку.

Использование

$PHPMailer = new PHPMailer();
$PHPMailer->base64EncodeWrapMB( $str, $linebreak );
$str(строка) (обязательный)
multi-byte text to wrap encode
$linebreak(строка)
string to use as linefeed/end-of-line
По умолчанию: null

Заметки

Код PHPMailer::base64EncodeWrapMB() WP 6.5.2

public function base64EncodeWrapMB($str, $linebreak = null)
{
    $start = '=?' . $this->CharSet . '?B?';
    $end = '?=';
    $encoded = '';
    if (null === $linebreak) {
        $linebreak = static::$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);

    $offset = 0;
    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
    return substr($encoded, 0, -strlen($linebreak));
}