PHP vCard class v2.0
Download (ZIP, 9 KB), Source code
These pages are using PHP vCard class v2.0 at the moment:
VCards are small files containing personal and address book data. These files can be attached to emails or used as export + import between different applications (Outlook, Thunderbird, Mac OS X Addressbook etc). As a premium member of Xing, you can also export all your contacts there and import them into the applications mentioned above or into your mobile phone.
So you can see, the format is quite old (1998), nowadays you would probably choose XML. But it is THE standard, we want to export the address data from our application as VCard. There are already some predefined classes (Contact_Vcard_Build, PHP vCard Class 2.0, class vcard), but I don’t want to use them here, because they either use the older 2.1 format or don’t support UTF-8. Here is a simple solution with a few lines of code:
This is of course only the beginning and a first test. But the principle is quite simple: Each line contains a property, like “Full name”, “Email address”, “Home address”, “Notes”, “Urls”, “Photos”, “Company”, “Birthday” and so on. Key and Value are separated by a colon, special options such as “PREF” or “TYPE” visible above are added separated by semicolons. More information can be found on the English Wikipedia page (the German one is not that extensive). You can also export multiple contacts in one vcf file, and object-oriented with Zend Framework it looks something like this:
So now all contacts are iterated and the individual vcard strings are concatenated. We use the appropriate functions here to disable the layout and the ViewRenderer and write all information into the response object.
I have implemented the function getContactAsVcardString() like this
The result is a file for download with all $contacts including details.
Talk to others and download addons at the forum!
|Features:||Complies to version 2.1 of the vCard specification
Supports the following attributes:
- Formatted Name
- Phone and fax numbers
- Address label
- email address