本文介绍了解码UTF-8编码的标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP imap从收件箱中读取电子邮件.它从标头中提取一些信息.标头之一如下所示:

I'm using PHP imap to read emails out of an inbox. It extracts some information from headers. One of the headers looks like this:

X-My-Custom-Header:=?UTF-8?B?RXVnZW4gQmFiacSH?=

X-My-Custom-Header: =?UTF-8?B?RXVnZW4gQmFiacSH?=

该编码字符串的原始值为EugenBabić.

The original value of that encoded string is Eugen Babić.

当我尝试使用PHP对该字符串进行解码时,我无法完全正确地找到它,ć总是被弄得一团糟.

When I try to decode that string using PHP, I can't get it quite right, the ć always comes back messed up.

我已经尝试过imap_utf8,imap_mime_header_decode和其他很多我不太记得的东西.他们要么根本什么都不退,要么像我前面提到的那样弄乱了ć.

I've tried imap_utf8, imap_mime_header_decode and a bunch of others I can't quite recall. They either don't return anything at all, or they mess up the ć as I mentioned before.

正确的解码方式是什么?

What is the correct way to decode this?

推荐答案

这是您在做的错误:您的HTML(由PHP生成)不是UTF-8编码的.因此,即使返回带重音符号的c,该页面也无法正确显示它.

Here's what you're doing wrong: You're HTML (as generated by the PHP) is not UTF-8 encoded. So even though it's returning the accented c, the page isn't displaying it correctly.

要对其进行修复,请将其添加到您的<head>标记中:

To fix it, add this in your <head> tag:

<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>

这篇关于解码UTF-8编码的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:34