LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   PHP Script for Importing vCards into a MySQL Database? (http://www.linuxquestions.org/questions/linux-software-2/php-script-for-importing-vcards-into-a-mysql-database-512996/)

amocjr 12-22-2006 06:36 PM

PHP Script for Importing vCards into a MySQL Database?
 
Does anybody have a PHP script for importing vCards into a MySQL database?

I'm using LAMP (Linux, Apache2, MySQL5, php4) on an old computer (running Debian) attached to my home network to provide a common contacts database my whole family can access using the browsers on their Windows boxes. (Think WebCalendar for names and addresses.) Our current contact managers (Palm and Outlook) export to CSV files, so I'll use those for the initial load into the family phone book, but I want to be able to use vCards to add new contacts to the database and update existing ones on a onesy-twosey basis.

Yes, I know vCards are XML files, and yes, I could read the vCard spec and figure out how to write a parser, but I figure this has got to be a problem somebody has already solved.

Thanks!

amocjr 01-20-2007 03:54 PM

I have found a solution to this problem.

There's a PHP class called Contact_Vcard_Parse.php that reads a Vcard file into an array called $cardinfo.

You use it as an include file in your PHP script. You can then access each piece of Vcard info by accessing the appropriate array element like this:

$last_name = ($cardinfo[0][N][0][value][0][0]);
$first_name = ($cardinfo[0][N][0][value][1][0]);


You can get Contact_Vcard_Parse.php here: http://distro.ibiblio.org/pub/linux/...card_Parse.php

You can find more information by googling it, but the script itself contains comments showing how to use it.


All times are GMT -5. The time now is 07:07 PM.