note 90242 added to function.mb-encode-mimeheader
| From: | Anonymous at osu1 dot php dot net | Date: | Sun, 12 Apr 2009 01:19:35 +0000 |
| Subject: | note 90242 added to function.mb-encode-mimeheader | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153102@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:
// 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;
}
----
Server IP: 200.24.234.70
Probable Submitter: 201.246.94.243
----
Manual Page -- http://www.php.net/manual/en/function.mb-encode-mimeheader.php
Edit -- https://master.php.net/note/edit/90242
Del: integrated -- https://master.php.net/note/delete/90242/integrated
Del: useless -- https://master.php.net/note/delete/90242/useless
Del: bad code -- https://master.php.net/note/delete/90242/bad+code
Del: spam -- https://master.php.net/note/delete/90242/spam
Del: non-english -- https://master.php.net/note/delete/90242/non-english
Del: in docs -- https://master.php.net/note/delete/90242/in+docs
Del: other reasons-- https://master.php.net/note/delete/90242
Reject -- https://master.php.net/note/reject/90242
Search -- https://master.php.net/manage/user-notes.php