vcard
vcard copied to clipboard
Non-latin letters break vCard
Here's the code I use for test:
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/vendor/jeroendesloovere/vcard/src/VCard.php';
use JeroenDesloovere\VCard\VCard;
// define vcard
$vcard = new VCard();
// define variables
$firstname = 'John';
$lastname = 'Doe';
$additional = '';
$prefix = '';
$suffix = '';
// add personal data
$vcard->addName($lastname, $firstname, $additional, $prefix, $suffix);
// add work data
$vcard->addCompany('Siesqo');
$vcard->addJobtitle('Web Developer');
$vcard->addEmail('[email protected]');
$vcard->addPhoneNumber(1234121212, 'PREF;WORK');
$vcard->addPhoneNumber(123456789, 'WORK');
$vcard->addAddress(null, null, 'street', 'worktown', null, 'workpostcode', 'Belgium');
$vcard->addURL('http://www.jeroendesloovere.be');
return $vcard->download();
Import into contact book on macOS Sierra 10.12.3 goes fine.
But when I use Cyrillic letters...
$firstname = 'Ðван';
$lastname = 'ÐеÑÑов';
I get this error when I try to import on macOS:
No cards added. No importable cards were found.
This is the generated broken card:
BEGIN:VCARD
VERSION:3.0
REV:2017-03-07T21:37:15Z
N;CHARSET=utf-8:ÐеÑÑов;Ðван;;;
FN;CHARSET=utf-8:Ðван ÐеÑÑов
ORG;CHARSET=utf-8:Siesqo
TITLE;CHARSET=utf-8:Web Developer
EMAIL;INTERNET:[email protected]
TEL;PREF;WORK:1234121212
TEL;WORK:123456789
ADR;WORK;POSTAL;CHARSET=utf-8:;;street;worktown;;workpostcode;Belgium
URL:http://www.jeroendesloo
To compare, when I make up a similar card in macOS Contacts app and export it, here's the working (importable) vCard I get:
BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//Mac OS X 10.12.3//EN
N:ÐеÑÑов;Ðван;;;
FN:Ðван ÐеÑÑов
ORG:Siesqo;
TITLE:Web Developer
EMAIL;type=INTERNET;type=HOME;type=pref:[email protected]
TEL;type=WORK;type=VOICE;type=pref:1234121212
TEL;type=WORK;type=VOICE:123456789
ADR;type=HOME;type=pref:;;street;worktown;;workpostcode;Belgium
item1.URL;type=pref:http://www.jeroendesloovere.be
item1.X-ABLabel:_$!<HomePage>!$_
X-ABUID:A350AF28-459F-420B-A068-BCC92001D906
END:VCARD
I notice there is no END:VCARD
in the end of the broken vCard, and url field is chopped.
When I simplify code further, leaving just first and last names, here's what's inside the .vcf
file the browser downloads:
BEGIN:VCARD
VERSION:3.0
REV:2017-03-07T21:50:05Z
N;CHARSET=utf-8:ÐеÑÑов;Ðван;;;
FN;CHARSET=utf-8:Ðван Ðе�
This "�" obviously does not belong here, and the rest of the vCard is trimmed.
For a name with latin letters, vCard download looks just fine:
BEGIN:VCARD
VERSION:3.0
REV:2017-03-07T21:53:45Z
N;CHARSET=utf-8:Petrov;Ivan;;;
FN;CHARSET=utf-8:Ivan Petrov
END:VCARD
When I use return $vcard->save();
instead of return $vcard->download();
, it does save the proper (not-trimmed) vCard on the harddrive. echo $vcard->getOutput();
works fine as well.
I tried nginx
and built-in php -S
server, the download()
method seems to be broken for both.