PHPMailer\PHPMailer

PHPMailer::decodeHeaderpublic staticWP 1.0

Decode an RFC2047-encoded header value Attempts multiple strategies so it works even when the mbstring extension is disabled.

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

Хуков нет.

Возвращает

Строку. The decoded header value

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

$result = PHPMailer::decodeHeader( $value, $charset );
$value(строка) (обязательный)
The header value to decode.
$charset(строка)
The target charset to convert to, defaults to ISO-8859-1 for BC.
По умолчанию: self::CHARSET_ISO88591

Код PHPMailer::decodeHeader() WP 6.9

public static function decodeHeader($value, $charset = self::CHARSET_ISO88591)
{
    if (!is_string($value) || $value === '') {
        return '';
    }
    // Detect the presence of any RFC2047 encoded-words
    $hasEncodedWord = (bool) preg_match('/=\?.*\?=/s', $value);
    if ($hasEncodedWord && defined('MB_CASE_UPPER')) {
        $origCharset = mb_internal_encoding();
        // Always decode to UTF-8 to provide a consistent, modern output encoding.
        mb_internal_encoding($charset);
        if (PHP_VERSION_ID < 80300) {
            // Undo any RFC2047-encoded spaces-as-underscores.
            $value = str_replace('_', '=20', $value);
        } else {
            // PHP 8.3+ already interprets underscores as spaces. Remove additional
            // linear whitespace between adjacent encoded words to avoid double spacing.
            $value = preg_replace('/(\?=)\s+(=\?)/', '$1$2', $value);
        }
        // Decode the header value
        $value = mb_decode_mimeheader($value);
        mb_internal_encoding($origCharset);
    }

    return $value;
}