jessevooges / php-vcard
A simple php library to create vcard files
dev-main
2022-09-12 11:18 UTC
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-06-12 17:10:35 UTC
README
This library can create a .vcf file or a string representation of a .vcf file with one or more vCards in it. All vCards are generated as a version 4.0 vCard.
Usage
<?php
use JesseVooges\PHPvCard\Parsers\VCardParser;
use JesseVooges\PHPvCard\Properties\Email;
use JesseVooges\PHPvCard\Properties\FormattedName;
use JesseVooges\PHPvCard\Properties\Name;
use JesseVooges\PHPvCard\Properties\Organisation;
use JesseVooges\PHPvCard\Properties\Telephone;
use JesseVooges\PHPvCard\Properties\Title;
use JesseVooges\PHPvCard\VCard;
$properties = [
new Name('Doe', 'John'),
new Telephone('+1-202-555-0125 '),
new Organisation('Company', 'Development'),
new FormattedName('John Doe'),
new Title('Developer'),
new Email('email@example.org')
];
$vCard = new VCard($properties);
$vCardParser = new VCardParser($vCard);
//Write to file
$path = __DIR__;
$vCardParser->toFile($path);
//Show string representation
echo $vCardParser->parse();
vCard properties
- FN (Full name): The full name of the object (as a single string). This is the only mandatory property.
- N (Name): The name of the object represented in structured parts
- NICKNAME: A nickname for the object
- PHOTO
- BDAY: Birth date of the object. Should only apply to Individual
- ANNIVERSARY: Should only apply to Individual
- GENDER: Should only apply to Individual
Addressing:
- ADDRESS: The address of the object
Communication:
- TEL: The telephone number(s)
- EMAIL: The email address(es)
- IMPP: The IMPP instant messaging contact information
- LANG: The language of the object
Geographical:
- TZ: The timezone of the object
- GEO: The geographical coordinates
Organizational:
- TITLE: The title of the object
- ROLE: The role of the object
- LOGO: The logo of the object
- ORG: The organisation related to the object
- MEMBER: Can only be used for Group Kind objects. Must point to other Individual or Organization objects.
- RELATED: Link to related objects.
Explanatory:
- CATEGORIES: The categories of the object
- NOTE: Notes about the object
- PRODID: The identifier of the product that created the vCard object
- REV: The revision datetime of the vCard object
- SOUND: Audio related to the object
- UID: A unique identifier for the object
- CLIENTPIDMAP: Not required
- URL: Any URL related to the object
Security:
- KEY: The security key of the object
Calendar:
- FBURL: Calendar Busy Time of the object
- CALADURI: Calendar Request of the object
- CALURI: Calendar Link of the object
Testing
Unit tests can be run in development by using ./vendor/bin/phpunit --verbose tests