I have string "test+=EC=B9=E8=F8=BE=FD=E1=ED=E9+test", it is an email body retrieved using imap_fetchbody(). I want to convert it to proper UTF-8 string "test+ěščřžýáíé+test".
I have tried functions imap_utf7_decode, imap_8bit, base64_decode, quoted_printable_decode with no success. Can you please advise me a function which will convert mentioned string to UTF-8?
I am using iconv_mime_decode($str, 0, "UTF-8"); for mail headers, but it does not work for mail body.
Thank you
The answer is in the accepted answer's comments!
Your input string appears to be ISO-8859-2, so you can use this function I have adapted from the comments in the PHP documentation.
function decode_qprint($str) {
$str = preg_replace("/\=([A-F][A-F0-9])/", "%$1", $str);
$str = urldecode($str);
$str = iconv("ISO-8859-2", "UTF-8", $str);
return $str;
}
Edit: Updated function per the comments:
function decode_qprint($str) {
$str = quoted_printable_decode($str);
$str = iconv('ISO-8859-2', 'UTF-8', $str);
return $str;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With