Create vCard file (.vcf)

Asked

Viewed 1,261 times

1

I want to create a vCard file in PHP. Insert values that come from an Sqlite database, and download the file.

1 answer

1

You have two different questions:

  1. List data from an Sqlite database
  2. Generate the vCard

The first problem is simple, just use the PDO or the Sqlite. Just connect, run the query and read the resource. This is basic and changes little thing from one DBMS to another.

For the second problem you have to study the specification vCard format, which is as difficult as any RFC, creating vCard manually from a more readable example or outsource.

There are several classes ready to create vCards. Some more complete than others and others more able to handle the basics. A quick Google search and you would find, for example, that article with an easy-to-use class:

require 'vCard.class.php'; // Altere se necessário

$vCard = new vcard;

$vCard -> data['first_name'] = 'Bruno Augusto';

$vCard -> download();

I filled out only my name because I’m lazy. p

The method download as the name suggests will force the download of the VCF file ready. Maybe you need a VCF reader. Here Windows 7 recognized automatically:

vCard

  • 1

    You have a Parse error in your code ;)

  • The Sublime fills the patience by closing the brackets of my arrays automatically. Thank you!

  • Always at the ready and +1 for the reply.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.