public static Unicode::mimeHeaderEncode($string)
Encodes MIME/HTTP headers that contain incorrectly encoded characters.
For example, Unicode::mimeHeaderEncode('tést.txt') returns "=?UTF-8?B?dMOpc3QudHh0?=".
See http://www.rfc-editor.org/rfc/rfc2047.txt for more information.
Notes:
string $string: The header to encode.
string The mime-encoded header.
public static function mimeHeaderEncode($string) { if (preg_match('/[^\x20-\x7E]/', $string)) { $chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75); $len = strlen($string); $output = ''; while ($len > 0) { $chunk = static::truncateBytes($string, $chunk_size); $output .= ' =?UTF-8?B?' . base64_encode($chunk) . "?=\n"; $c = strlen($chunk); $string = substr($string, $c); $len -= $c; } return trim($output); } return $string; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Utility!Unicode.php/function/Unicode::mimeHeaderEncode/8.1.x