PHP,IMAP和Outlook 2010-文件夹名称编码不同吗? [英] PHP, IMAP and Outlook 2010 - folder names encoding is different?

查看:148
本文介绍了PHP,IMAP和Outlook 2010-文件夹名称编码不同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用php(带有symfony2)开发电子邮件客户端,并且我在名称中包含非ASCII字符的文件夹时遇到了问题.

Im developing e-mail client in php (with symfony2) and i have problem with folders with non-ascii characters in name.

在php应用程序中创建的文件夹在同一应用程序中正确可见.与Outlook中相同,在Outlook中创建的Outlook外观也不错.在其他情况下则不然.在Outlook中创建的文件夹在php中无法正确显示,反之亦然.

Folder created in php app is visible in same app correctly. Same in Outlook, created in outlook looks good in outlook. In other cases not. Folder created in outlook is not displayed correctly in php and vice-versa.

我使用utf-7在php中编码文件夹名称.哪种编码使用Outlook?

Im using utf-7 to encode folder names in php. Which encoding uses Outlook?

示例:名为Wysłąne"(拼写波兰语,意为已发送")的文件夹,第一个由php在utf7中编码,第二个在Outlook中创建:

Example: Folder named "Wysłąne" (misspelled polish word meaning "sent"), first one is encoded in utf7 by php, and second created in Outlook:

PHP:

Wys&xYLEhQ-ne

Outlook:

Wys&AUIBBQ-ne

为什么不同?如何以相同的编码制作它?

Why it differs? How to make it in same encoding?

推荐答案

您的源字符编码中似乎存在混淆. imap_utf7_encode(及类似代码)要求您使用ISO-8859-1编码的字符串.

There seems to be a mixup in your source character encoding. imap_utf7_encode (and similar) expect your string in ISO-8859-1 encoding.

AFAICT无法在ISO-8859-1中代表Wysłąne.表示为UTF-8的Wysłąne"变为(十六进制字节)

AFAICT there is no way to represent Wysłąne in ISO-8859-1. "Wysłąne" represented as UTF-8 becomes (hex bytes)

byte value (hex)    57, 79, 73, C5 82, C4 85, 6E 65
unicode character   W   y   s   ł      ą      n  e

当解码时,PHP结果Wys& xYLEhQ-ne为"Wys얂쒅ne".其中的两个特殊字符是韩文字符,分别具有代码点U + C582和U + C485.因此,似乎以某种方式尝试了每个字符的翻译,其中两个字符的UTF-8表示被解释为Unicode代码点.

The PHP result Wys&xYLEhQ-ne when decoded is "Wys얂쒅ne". The the two special characters therein are Korean characters with code points U+C582 and U+C485 respectively. So it appears a character-per-character translation is somehow attempted, where the UTF-8 representation of two of the characters is interpreted as Unicode code points instead.

解决此问题的最简单方法是使用具有mb_convert_encoding功能的mbstring扩展名.

The simplest way to fix this is to use the mbstring extension which has the mb_convert_encoding function.

$utf7encoded = mb_convert_encoding($utf8SourceString, "UTF7-IMAP","UTF-8")
$decodedAsUTF8 = mb_convert_encoding($utf7String,"UTF-8", "UTF7-IMAP")

这篇关于PHP,IMAP和Outlook 2010-文件夹名称编码不同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆