Can anyone help me to convert csv contact to vcard format?

Discussion in 'Programming' started by viruthagiri, Jul 25, 2010.

Thread Status:
Not open for further replies.
  1. #1
    Hello friends,
    I need to convert 15 million email contacts immediately. I have all the contacts in csv format. But my client needs it in vcard format. I've been searched all over the internet. I couldn't find a converter or script to convert csv file into vcard format.
    I found a site that offering this conversion online. But it is not possible to convert all these 15 million online. So can anyone help me. Or tell me is there any product available online.
    Or please give me some ideas to convert it immediately. Thanks to everyone who willing to help me. Waiting for your reply
     
    Solved! View solution.
    viruthagiri, Jul 25, 2010 IP
  2. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #2
    This could be done with PHP.
    So you basically need to convert a file, such as
    Firstname,Lastname,first@last.com
    John,Smith,john@smith.com
    Code (markup):
    into 2 separate files
    BEGIN:VCARD
    VERSION:3.0
    N:Lastname;Firstname
    FN:Firstname Lastname
    EMAIL:first@last.com
    Code (markup):
    and
    BEGIN:VCARD
    VERSION:3.0
    N:Smith;John
    FN:John Smith
    EMAIL:john@smith.com
    Code (markup):
    or am I wrong?
     
    iAreCow, Jul 25, 2010 IP
  3. viruthagiri

    viruthagiri Active Member

    Messages:
    232
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    95
    #3
    Yes you are right. Can you give the code?. I'll be very thankful to you
     
    viruthagiri, Jul 25, 2010 IP
  4. #4
    <?php
    $file = file("contactlist.cvs", FILE_IGNORE_NEW_LINES); // Open the original CVS file (change contactlist.cvs to your filename, keep the quotes)
        foreach ($file as $line) { // Process each line
        $exp = explode(",",$line); // Explode by commas
        $vcard_file = fopen($exp[0]." ".$exp[1].".vcf","w"); // Open VCard file for reading (Format: Firstname Lastname.vcf)
        $vcard_contents = "BEGIN:VCARD
    VERSION:3.0
    N:$exp[1];$exp[0]
    FN:$exp[0] $exp[1]
    EMAIL:$exp[2]
    END:VCARD"; // That's the block for the VCard file contents
        fwrite($vcard_file,$vcard_contents); // Write contents to VCard file
        fclose($vcard_file); // Close VCard file
    }
    ?>
    PHP:
    Change the 2nd line, be sure not to process all 15 million lines by once if you don't have plenty of RAM and CPU power.
    PS: Running this script requires PHP, since it could also be run as a CLI script (not tested though), you don't necessarily need a web server installed, but just PHP.

    EDIT: Here's the CLI version, you only need PHP installed
    Code: http://paste2.org/p/927134
    Running: http://www.alt-php-faq.org/local/86/
     
    Last edited: Jul 25, 2010
    iAreCow, Jul 25, 2010 IP
  5. viruthagiri

    viruthagiri Active Member

    Messages:
    232
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    95
    #5
    Thanks dude, I'll check it and tell you the result
     
    viruthagiri, Jul 25, 2010 IP
  6. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Okay, feedback would be appreciated!
     
    iAreCow, Jul 25, 2010 IP
  7. viruthagiri

    viruthagiri Active Member

    Messages:
    232
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    95
    #7
    Hey thank you dude. Your code works perfectly. Thankyou once again. It took me 2 hours to convert the whole 30 million contacts. But all my efforts are wasted. I delivered my product. But my client cheated me without making payment. I'm really upset.
     
    viruthagiri, Jul 25, 2010 IP
  8. jinmath

    jinmath Peon

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    okies but you now have a ready database of 30 million , use these to send cpa offers and make a million out of that

    may be this is the way some idiot buyer learn a lesson
     
    jinmath, Jul 26, 2010 IP
  9. viruthagiri

    viruthagiri Active Member

    Messages:
    232
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    95
    #9
    Ya, i'll try that
     
    viruthagiri, Jul 26, 2010 IP
Thread Status:
Not open for further replies.