PHP Classes

PHP vCard Library: Import and export contact lists in vCard format

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 412 All time: 6,479 This week: 48Up
Version License PHP version Categories
imexvcard 1.0.5Freely Distributable5PHP 5, Files and Folders, User Manage..., P...
Description 

Author

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.

Picture of Stefan Kientzler
  Performance   Level  
Name: Stefan Kientzler is available for providing paid consulting. Contact Stefan Kientzler .
Classes: 19 packages by
Country: Germany Germany
Age: 57
All time rank: 71446 in Germany Germany
Week rank: 33 Up1 in Germany Germany Up
Innovation award
Innovation award
Nominee: 11x

Winner: 6x

Recommendations

What is the best PHP vcard parser class?
Upload vCard data into a MySQL database

What is the best PHP vcard export and import class?
Parse vcard values in mobile contact list

Example

<?php
declare(strict_types=1);

use
SKien\VCard\VCard;
use
SKien\VCard\VCardAddress;
use
SKien\VCard\VCardContact;
require_once
'autoloader.php';
require_once
'blobPortrait.php';

   
$oVCard = new VCard();
   
$oVCard->setEncoding('Windows-1252');

   
// just create new contact
   
$oContact = new VCardContact();
   
$oContact->setName('von Flake', 'Wiki');
   
$oContact->setOrganisation('Company 4711');
   
$oContact->addHomepage('www.firstpage.de');
   
$oContact->addHomepage('www.secondpage.uk');

   
$oContact->setDateOfBirth('1982-07-26');

   
$oAddress = new VCardAddress();
   
$oAddress->setStr('Bärenweg. 4');
   
$oAddress->setPostcode('54321');
   
$oAddress->setCity('Musterstadt');
   
$oAddress->setType(VCard::HOME);
   
$oContact->addAddress($oAddress, true);

   
$oContact->addPhone('01234 5678', VCard::HOME, false);
   
$oContact->addPhone('0123 89765456', VCard::CELL, true);

   
$oAddress = new VCardAddress();
   
$oAddress->setStr('Companystr. 8');
   
$oAddress->setPostcode('65432');
   
$oAddress->setCity('Musterstadt');
   
$oAddress->setRegion('Baden-Würtemberg');
   
$oAddress->setCountry('Deutschland');
   
$oAddress->setType(VCard::WORK);
   
$oContact->addAddress($oAddress, false);

   
$oContact->addPhone('01234 98356', VCard::WORK, false);

   
$oContact->addEMail('private@web.de', true);
   
$oContact->addEMail('president@club.de', false);
   
$oContact->addEMail('work@company.de', false);

   
$oContact->addCategory('Krieger');
   
$oContact->addCategory('Wikinger');

   
$strNote = "Hier steht ein mehrzeiliger Text," . PHP_EOL;
   
$strNote .= "der auch Umlaute (ä,ö,ü) und Sonderzeichen" . PHP_EOL;
   
$strNote .= "(@,~,§,$) enthä....";
   
$oContact->setNote($strNote);

   
// insert multiple contacts
   
$oContact->setPortraitBlob(getBlobPortrait()); // Wiki von Flake
   
$oVCard->addContact($oContact);

   
// change name and portrait ... all other properties remains valid!
   
$oContact->setName('von Flake', 'Ilvy');
   
$oContact->setPortraitFile('images/sample2.png'); // Ilvy von Flake
   
$oContact->setDateOfBirth(477270000);

   
$oVCard->addContact($oContact);

   
// change name again and add some additional info....
   
$oContact->setName('von Flake', 'Halvar');
   
$oContact->setPrefix('Mr.');
   
$oContact->setSuffix('Häuptling');
   
$oContact->setPortraitFile('images/sample3.bmp'); // Halvar von Flake
   
$oContact->setDateOfBirth(new \DateTime('1964-04-19'));
   
$oVCard->addContact($oContact);

   
// and write to file
   
$oVCard->write('test.vcf', isset($_GET['test']));


Details

PHP vCard Library: Import and export contacts in vCard format

Latest Stable Version License Donate Minimum PHP Version Scrutinizer Code Quality

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.

New in Version 1.1.0

  • Support of multiple homepages per contact
  • new method `VCard::listContacts() : array`

Installation

You can download the Latest release version from PHPClasses.org

Usage

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);
        }
    }

> Note: > If data to be exported comes from a database/table with collation latinX_yyyyy, the character > encoding detection order from PHP may have to be set with > mb_detect_order('UTF-8, Windwos-1252, ISO-8859-XX') before using the class (replace X,y to fit your encoding).

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->setType(VCard::HOME);
    $oAddress->setStr('Bärenweg. 4');
    // ... set more properties of oAddress
    $oContact->addAddress($oAddress, true);

    // WORK address
    $oAddress = new VCardAddress();
    $oAddress->setType('WORK');
    $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('private@web.de', true);
    $oContact->addEMail('president@club.de', false);
    $oContact->addEMail('work@company.de', false);
    
    // insert contact
    $oVCard->addContact($oContact);
    
    // ... may continue with further contacts

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


  Files folder image Files (21)  
File Role Description
Files folder imagedoc (1 file)
Files folder imageimages (4 files)
Files folder imageSKien (1 directory)
Accessible without login Plain text file autoloader.php Aux. Auxiliary script
Accessible without login Plain text file blobPortrait.php Aux. Auxiliary script
Accessible without login Plain text file ExportTest.php Example Test for Export vCard
Accessible without login Plain text file githubwiki.xml Data Auxiliary data
Accessible without login Plain text file ImportSelect.php Aux. form to open vCard
Accessible without login Plain text file ImportTest.php Example Test for Import vCard
Accessible without login Plain text file LICENSE Lic. License
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file readme.md Doc. readme
Accessible without login Plain text file test.vcf Data sample vCard

  Files folder image Files (21)  /  doc  
File Role Description
  Accessible without login Plain text file vCard-rfc2426.pdf Doc. RFC 2426 Specification

  Files folder image Files (21)  /  images  
File Role Description
  Accessible without login Image file sample1.jpg Photo sample JPG image
  Accessible without login Image file sample2.png Photo sample PNG image
  Accessible without login Image file sample3.bmp Photo sample BMP image
  Accessible without login Image file sample4.gif Photo sample GIF image

  Files folder image Files (21)  /  SKien  
File Role Description
Files folder imageVCard (6 files)

  Files folder image Files (21)  /  SKien  /  VCard  
File Role Description
  Plain text file VCard.php Class Class source
  Plain text file VCardAddress.php Class Class source
  Plain text file VCardContact.php Class Class source
  Plain text file VCardContactReader.php Class Class source
  Plain text file VCardContactWriter.php Class Class source
  Plain text file VCardHelper.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:412
This week:0
All time:6,479
This week:48Up