note 16332 rejected from function.ereg-replace by jimw

From: Date: Thu, 25 Oct 2001 23:10:08 +0000
Subject: note 16332 rejected from function.ereg-replace by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-19435@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);

« previous php.notes (#19435) next »