note 16332 added to function.ereg-replace
| From: | fredric dot jacobsson at telia dot com | Date: | Thu, 25 Oct 2001 10:13:06 +0000 |
| Subject: | note 16332 added to function.ereg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-19413@lists.php.net to get a copy of this message | ||
When using mail() and sending a mail to someone with a "bad" email-reader they get wrong
characters. Like sending an email from a PC to a Mac-user and vice versa. I'm using the
following code in Perl for encoding special characters in an email, especially nordic chars like å,
ä, ö. It works perfectly! How can I do the same with PHP?
sub koda_qp {
my ($kodad, $radbruten) = ($_[0], "");
$kodad =~ s/([^ \t\n!-<>-~])/sprintf("=%02X", ord ($1))/eg;
$kodad =~ s/([ \t]+)$/join '',map {sprintf("=%02X", ord ($_))}
(split '', $1)/meg;
while ($kodad) {
if ($kodad =~ s/^(.{73}[^=]{0,2})//) { $radbruten .="$1=\n"; }
else {
$kodad =~ s/^(.*)\n?//;
$radbruten .="$1\n";
}
}
return $radbruten;
}
// And for the mail-headers:
sub koda_qp_huvud {
$huvud = $_[0];
$huvud =~ s/([^ \t\n!-<>-~])/sprintf("=?iso-8859-1?Q?=%02X?=",
ord($1))/eg;
return $huvud;
}
Invoked with:
$body = koda_qp($in_text_okodad);
$header = koda_qp_huvu($in_rubrik);
--
http://www.php.net/manual/en/function.ereg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+16332
http://master.php.net/manage/user-notes.php?action=delete+16332
http://master.php.net/manage/user-notes.php?action=reject+16332