在 Outlook 中 PHP 生成的电子名片的字符编码问题

jsu*_*ssa 5 php vcf-vcard character-encoding

我们在尝试在 PHP 中创建 vcard 时遇到了字符编码问题。

在 Outlook 中,使用特殊字符的名称会被扭曲,例如“é”变成了“é”。

我们更新了 Windows 字符编码的标题和 FN 和 N 部分,但问题仍然存在。

感谢任何建议。

电子名片摘录:

BEGIN:VCARD
VERSION:3.0
REV:2013-03-27 19:37:46
FN;CHARSET=Windows-1252:Namé S. Nameé
N;CHARSET=Windows-1252:Namé;Namé;;;
TITLE:Associate
ORG:Company
EMAIL;TYPE=internet,pref:name@abc.com
TZ:-0400
END:VCARD
Run Code Online (Sandbox Code Playgroud)

Vcard 的 PHP 头文件:

    header("Content-type: text/x-vcard; charset=windows-1252;");
    header("Content-Length: ".strlen($vc->card));
    header("Content-Disposition: attachment; filename=".$vcard_name.".vcf");
    header("Pragma: public");
Run Code Online (Sandbox Code Playgroud)

jsu*_*ssa 3

还有一些类似的问题,但似乎没有什么是明确的。通过在 vcard 字段中指定字符集,看起来我已经成功了一半。

我终于通过将以下内容更改为“utf-8;”使其工作:

 header("Content-type: text/x-vcard; charset=CHARSET=utf-8;");
Run Code Online (Sandbox Code Playgroud)

vcard 本身的名称字段也是如此。指定utf-8似乎已经解决了特殊字符的显示问题:

$this->card .= "FN;CHARSET=utf-8:".$new_display_name.$this->data['short_mode'];
    $this->card .= "N;CHARSET=utf-8:"
Run Code Online (Sandbox Code Playgroud)

在 Outlook 2007 中打开,所有重音字符均按预期显示。