PHP Classes


Recommend this page to a friend!
  Classes of Stefan Kientzler  >  PHP vCard Library  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: readme
Class: PHP vCard Library
Import and export contact lists in vCard format
Author: By
Last change: Update
PHP m7.4 / PSR-4 / docBlock

- renamed namespace to fit PSR-4 recommendations
- added missing PHP 7.4 type hints
- docBlock changes
repositiory created
Date: 1 year ago
Size: 3,301 bytes


Class file image Download

PHP vCard Library: Import and export contacts in vCard format

Latest Stable Version License Donate Minimum PHP Version

This package can be used to import and export contact lists in vCard format.

It can create a new contact list from scratch and export it in vCard format - .vcf - compliant with the version 3.0 of the format specification (RFC 2426).

The package can also import an existing VCF file and makes it available to the PHP applications as an iterator that returns the details of each contact that was found in the vCard file. The package supports vCard format version 2.1 and 3.0.


You can download the Latest release version from


Import VCF

	// create object and read file
	$oVCard = new VCard();
	$iContactCount = $oVCard->read($strFilename);
	for ($i = 0; $i < $iContactCount; $i++) {
		// iterate to importetd contacts
		$oContact = $oVCard->getContact($i);
		$strName = $oContact->getName();
        // ... read more properties
		// iterating through all addresses
		$iCount = $oContact->getAddressCount();
		for ($j = 0; $j < $iCount; $j++) {
			$oAddress = $oContact->getAddress($j);
			$strStr = $oAddress->getStr();
            // ... read more properties

		// phonenumbers
		$iCount = $oContact->getPhoneCount();
		for ($j = 0; $j < $iCount; $j++) {
			$aPhone = $oContact->getPhone($j);
			$strType = $aPhone['strType'];
            $strPhone = $aPhone['strPhone'];

		$iCount = $oContact->getEMailCount();
		for ($j = 0; $j < $iCount; $j++) {
			$strMail = $oContact->getEMail($j);

Export VCF

	// create object
	$oVCard = new VCard();

	// just create new contact
	$oContact = new VCardContact();
	$oContact->setName('von Flake', 'Wiki');
	$oContact->setOrganisation('Company 4711');

    // HOME address
	$oAddress = new VCardAddress();
	$oAddress->setStr('Bärenweg. 4');
    // ... set more properties of oAddress
	$oContact->addAddress($oAddress, true);

    // WORK address
	$oAddress = new VCardAddress();
	$oAddress->setStr('Companystr. 8');
    // ... set more properties of oAddress
	$oContact->addAddress($oAddress, false);

    // phones
	$oContact->addPhone('01234 5678', VCard::HOME, false);
	$oContact->addPhone('0123 89765456', VCard::CELL, true);
	$oContact->addPhone('01234 98356', VCard::WORK, false);
    // e-mails
	$oContact->addEMail('', true);
	$oContact->addEMail('', false);
	$oContact->addEMail('', false);
	// insert contact
    // ... may continue with further contacts

	// and write to file
	$oVCard->write('test.vcf', false);    

For more information send a message to info at phpclasses dot org.