首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用PHP将电子邮件解码到UTF-7

用PHP将电子邮件解码到UTF-7
EN

Stack Overflow用户
提问于 2017-09-22 21:41:04
回答 1查看 326关注 0票数 0

我一直在尝试将许多IMAP消息体转换为更具可读性的内容(UTF-8或类似内容)。我似乎找不到一个现成的函数来工作。

下面是我试图解码的一个例子:

代码语言:javascript
复制
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

(在上面的示例中,任何"=“都应该有一个换行符)

我尝试过的几件事:

代码语言:javascript
复制
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检索到的邮件正文的?

我还能做些什么呢?人们必须一直这样做,但我似乎找不到解决办法.

谢谢你,罗格

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-22 21:50:56

你实际上不是在处理UTF-7的编码。你实际上看到的是引文-可打印

php包含一个函数来解码

实际上,我已经很长一段时间没有编写php了,所以请原谅我的风格失败,下面是一个解码文本的例子:

代码语言:javascript
复制
<?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));
?>

当运行时,它生成:

代码语言:javascript
复制
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.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46373599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档