我使用一个PHP类来生成vcard: http://www.troywolf.com/articles/php/class_vcard/
但是重音字符不能正确显示。我猜这与字符编码有关,但我一直无法找到一种方法来改变它。
我所有的文件都保存为没有BOM的UTF8格式,下面是脚本的输出:
BEGIN:VCARD
VERSION:3.0
CLASS:PUBLIC
PRODID:-//www.bla.com//Version 1//EN
REV:2011-08-30 03:19:49
FN:Heïdi DABODFE
N:DABODFE;Heïdi;;;
TITLE:Directrice
ORG:blablabla
ADR;TYPE=work:;;2 Imp. Les Plataness;Mirepoix;;09500;France
EMAIL;TYPE=internet,pref:contact@bla.com
TEL;TYPE=work,voice:05 61 68 64 38
PHOTO;ENCODING=BASE64;TYPE=JPEG:
/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkc
gSlBFRyB2NjIpLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCA
wKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LD
RQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgA
YABgAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwM
CBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJS
YnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVl
peYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX2
9/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAE
CdwABAgMRBAUhMQYSQ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dTyM4x7Vk6xcxvrsNjPI0Wn2hW3BUZ2gfefHcsSWP1+la2q3dhpGlW1ha38OryJ
eNdK0Qfy4o8ABcsFOWwCQBgbRW576k3bzPZfBXx51LwBdJaS2Md3p2547uXzw8E67jjCYwuBxt9
gMdq+l/h98VNI8TWsc/hrVol3fe0u9kwAfRH5I+hB/AV+exuLSOJLjzFku2mD+XGCFCY+bdkYBJ
xgD39q3NLe8luje25fT0MZEM0c6wbmC+jHL5Ixgf0rCdJPVaHg47I6GJXPB8kvwfyP0yi8cRWwA
1OzuLBum90zGf+BjK/rWhB4w0e5UGPUIXB/utn+Vfn94R/aL8Z+FElt7nVGMsJCiC5XB9+owPy/
nXYw/teak2mJd3uh2Fy7StEd0SueFBySQOuf0rF05o+WqZBjqbtFKS8n/AJ2Ps248ZaNajMmoQr
7M2P51Qn8atdIf7MsJ7kf89pV8uIf8CbAP4Z+lfJ0f7WczaYbuBdN02VVfNvFbkT7h90LhSpB4y
SRivNNY/aD8U+MZGTU9ZNpaE5kSHcGZcHheCM/lQqc2OjkONqv3lypdz6n+I/xk0LwlC82t6lFr
F6oJj021bMII/vd3x6YA45Hevlb4kfFXUvi7JKXuQAQBDYlxHtO4YxnAPAICgknI7jNefLf3etw
mERtdXO4M8znLBcnJLE4A5A5qC9sP7K1C2mXKWjFSs3mLKqtgErvXgkH/APVW8KSjq9z67AZPQw
L5pPmn3/4BXPnalLIqyRq1rCxRWyCVTLHHGMgZPOOnrVmLTtSfTo/It7ezmnjCq8t2kUsyZBG1G
YHkgcgc4475g04xLrscKTNPZlmkePccSqoLbT9do/Os+zeHxDqly+qaitpLMjOlxOG2GTsG2gkD
8K3PbnJv0P/Z
URL;TYPE=work:www.bla.com
NOTE:bla
TZ:-0500
END:VCARD
任何帮助都非常感谢
您是否尝试了其他程序来导入这个VCARD?对于3.0版本,应该可以使用utf-8,除非它的名称以"O"开头,以"tlook"结尾^^
看看是否适合你:
FN;CHARSET=utf-8:Heïdi DABODFE
N;CHARSET=utf-8:DABODFE;Heïdi;;;
如果程序真的遵循标准就好了!它们应该是这样工作的:
- 对于vCard 2.1,您应该使用
FN;CHARSET=utf-8;ENCODING=8BIT:Heïdi DABODFE
,因为它也可以是ENCODING=QUOTED-PRINTABLE
,许多程序确实使用它。我认为Outlook吃得很好,然而雷鸟拒绝编码部分(雷鸟也出口据称v2.1 vCards没有字符集/编码信息)。 - 对于vCard 3.0,为每个属性使用不同字符集的可能性消失了(它有什么意义?)。在传输vCard时,您将使用内容类型MIME头,这就是要指定字符集的地方(RFC第5节说)。然而,你通常不会在vCard文件中找到内容类型的头,大多数程序只是使用
FN;CHARSET=utf-8;ENCODING=8BIT:Heïdi DABODFE
作为2.1。 - 对于vCard 4.0, vCard文件的字符集总是UTF-8,没有办法覆盖这一点,在MIME头中指定不同的字符集是无效的(RFC的3.1节)。
现实情况是,大多数程序对vCard都不太在意,并且使用相同的代码来处理版本2.1、3.0和4.*。我使用UTF-8生成vCard以满足RFC 6350,使用CHARSET=utf-8
来满足vCard 2.1规范,避免ENCODING=8BIT
来满足雷鸟,我目前正在考虑添加MIME头。
令人遗憾的是,在2015年仍然很难处理这个问题,这听起来更像是20世纪80年代的问题。
解决方案是这样的,
假设$vcf是包含utf-8字符的字符串:
file_put_contents($dir.$filename, utf8_decode($vcf));
法语utf-8字符在Outlook中正确显示,刚刚发现。