PHP code example of jelgblad / vcard

1. Go to this page and download the library: Download jelgblad/vcard library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jelgblad / vcard example snippets


use jelgblad\VCard\VCard;

// Create new VCard
$vcard = new VCard();

// Add some properties to VCard
$vcard->createProp('FN', 'Jonas Elgblad');
$vcard->createProp('N', ['Elgblad', 'Jonas']);
$vcard->createProp('URL', 'https://github.com/jelgblad')->createParam('TYPE', 'github');
$vcard->createProp('EXPERTISE', 'PHP')->createParam('LEVEL', 'moderate');

echo $vcard;

use jelgblad\VCard\VCard;

$input = '
  BEGIN:VCARD
  VERSION:4.0
  FN:John Doe
  N:Doe;John
  END:VCARD';

// Since .vcf-files can contain more than one vCard, VCard::parse() returns an array of all the parsed vCards.
$vcards = VCard::parse($input);

foreach ($vcards as $i => $vcard) {
  printf("vCard %d:\n", $i + 1);
  printf("Name: %s\n", $vcard->getProp('FN')->getValue());
}