我一直在尝试将许多IMAP消息体转换为更具可读性的内容(UTF-8或类似内容)。我似乎找不到一个现成的函数来工作。
下面是我试图解码的一个例子:
President Trump signed an executive order Thursday tar= geting North Korea=E2=80=99s trading partners, calling it a =E2=80=9Cpowerful=E2= =80=9D new tool aimed at isolating and de-nuclearizing the regime.
More on thi= s: http://www.foxnews.com= /politics/2017/09/21/trump-signs-executive-order-targeting-north-koreas-tra= ding-partners.html(在上面的示例中,任何"=“都应该有一个换行符)
我尝试过的几件事:
iconv("UTF-8", "Windows-1252//TRANSLIT//IGNORE", $data);
//this resulted in a server error 500
imap_mime_header_decode($data);
//this outputs an array (just something that I tried; yes, I know that it is only good for headers)
iconv_mime_decode($test, 0, "ISO-8859-1");
//This works for a few messages (plaintext ones) but does not output anything for the example above; for others, it only outputs part of the message body
mb_convert_encoding($test, "UTF8");
//this results in another internal server error!
$data = str_replace("=92", "'", $data);
//I have also tried to manually find and replace an occurrence of a utf-7 (I guess) encoded string不管怎样,有些事情我做错了,但不确定是什么。你们是如何阅读IMAP检索到的邮件正文的?
我还能做些什么呢?人们必须一直这样做,但我似乎找不到解决办法.
谢谢你,罗格
发布于 2017-09-22 21:50:56
你实际上不是在处理UTF-7的编码。你实际上看到的是引文-可打印。
php包含一个函数来解码
实际上,我已经很长一段时间没有编写php了,所以请原谅我的风格失败,下面是一个解码文本的例子:
<?php
$s = 'President Trump signed an executive order Thursday tar= geting North Korea=E2=80=99s trading partners, calling it a =E2=80=9Cpowerful=E2= =80=9D new tool aimed at isolating and de-nuclearizing the regime.';
// It's unclear why I have to replace out `= `, I have a feeling these
// are actually newlines and copy paste error?
echo quoted_printable_decode(str_replace('= ', '', $s));
?>当运行时,它生成:
President Trump signed an executive order Thursday targeting North Korea’s trading partners, calling it a “powerful” new tool aimed at isolating and de-nuclearizing the regime.https://stackoverflow.com/questions/46373599
复制相似问题