June 7, 2011

LBHToolkit: Using the PHP5 vCard Generator

Kevin Hallmark @ 9:30 pm —

I was having a lot of trouble finding a suitable vCard generator for one of my personal projects last year, so I whipped up this little class to let you quickly generate a vCard in an object oriented way.

The example below can help you use the class. It’s actually really easy. Just instantiate the class, set properties to it with standard object notation, and then call “Generator::create()”. A list of all the fields can be found in LBHToolkit/vCard/Generator.php

LBHToolkit vCard Example

<?php
// Include the class
require("library/LBHToolkit/vCard/Generator.php");

$vcard = new LBHToolkit_vCard_Generator();

// Name, requires a little knowledge of vCard.
$vcard->formatted_name = "Kevin Hallmark";
$vard->name = 'Hallmark,Kevin';

//Company nae
$vcard->company = "Little Black Hat";

// Assign an address
$vcard->work_address = "123 Fake St";
$vcard->work_city = 'Orlando';
$vcard->work_state = 'FL';
$vcard->work_zip = "12345";

$vcard->work_phone = '555-555-5555';

$vcard->note = "Kevin is a nice guy.";

 

echo $vcard->create();