I want to create a vCard file in PHP. Insert values that come from a SQLite database, and download the file.
I want to create a vCard file in PHP. Insert values that come from a SQLite database, and download the file.
You have two different questions:
The first problem is simple, just use PDO or SQLite . Just connect, run the query and read the resource. This is basic and changes little from one DBMS to another.
For the second problem you have to study the specification of the vCard format, which is quite difficult as any RFC, create the vCard manually from a more readable example or outsource.
There are several classes ready for creating vCards. Some are more complete than others and others that give the basics. A quick Google search and you'd find this 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 just filled my name because I'm lazy. : p
The download method as the name suggests will force the download of the VCF file ready. You may need a VCF reader. Here Windows 7 automatically recognized: