note 90242 modified in function.mb-encode-mimeheader by danbrown

From: Date: Sun, 12 Apr 2009 03:32:55 +0000
Subject: note 90242 modified in function.mb-encode-mimeheader by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153109@lists.php.net to get a copy of this message
I could not find a PHP function to MIME encode the name for a n email address. Input = "Karl Müller<kmueller@gmx.de>" Output = "Karl%20M%FCller<kmueller@gmx.de>" I wrote it on my own: <?php // required to encode names in email addresses // replace " " with "%20" // replace "ü" with "%FC" // replace "%" with "%25" etc.... // Use "%" as Delimiter for MIME // Use "=" as Delimiter for Quoted Printable // Input string must be UTF8 encoded public static function EncodeMime($Text, $Delimiter) { $Text = utf8_decode($Text); $Len = strlen($Text); $Out = ""; for ($i=0; $i<$Len; $i++) { $Chr = substr($Text, $i, 1); $Asc = ord($Chr); if ($Asc > 0x255) // Unicode not allowed { $Out .= "?"; } else if ($Chr == " " || $Chr == $Delimiter || $Asc > 127) { $Out .= $Delimiter . strtoupper(bin2hex($Chr)); } else $Out .= $Chr; } return $Out; } ?> --was-- I could not find a PHP function to MIME encode the name for a n email address. Input = "Karl Müller<kmueller@gmx.de>" Output = "Karl%20M%FCller<kmueller@gmx.de>" I wrote it on my own: // required to encode names in email addresses // replace " " with "%20" // replace "ü" with "%FC" // replace "%" with "%25" etc.... // Use "%" as Delimiter for MIME // Use "=" as Delimiter for Quoted Printable // Input string must be UTF8 encoded public static function EncodeMime($Text, $Delimiter) { $Text = utf8_decode($Text); $Len = strlen($Text); $Out = ""; for ($i=0; $i<$Len; $i++) { $Chr = substr($Text, $i, 1); $Asc = ord($Chr); if ($Asc > 0x255) // Unicode not allowed { $Out .= "?"; } else if ($Chr == " " || $Chr == $Delimiter || $Asc > 127) { $Out .= $Delimiter . strtoupper(bin2hex($Chr)); } else $Out .= $Chr; } return $Out; } http://php.net/manual/en/function.mb-encode-mimeheader.php

« previous php.notes (#153109) next »