PHP Classes

Why repeat to other contact below

Recommend this page to a friend!

      PHP vCard Library  >  All threads  >  Why repeat to other contact below  >  (Un) Subscribe thread alerts  
Subject:Why repeat to other contact below
Summary:Why repeat to other contact below
Messages:2
Author:Hasan Basri
Date:2020-09-26 17:31:20
 

  1. Why repeat to other contact below   Reply   Report abuse  
Picture of Hasan Basri Hasan Basri - 2020-09-26 17:31:20
Why repeat to other contact below ?
How to set ?
code like this

$oVCard = new VCard();

// just create new contact
$oContact = new VCardContact();
$oContact->setName('Basri', 'Hasan');
$oContact->addPhone('62822*****2319', VCard::CELL, true);
$oVCard->addContact($oContact);

// change name and portrait
$oContact->setName('Fredi', 'Tegar');
$oContact->addPhone('62822*****2322', VCard::HOME, true);
$oContact->addPhone('62822*****3255', VCard::HOME, true);
$oVCard->addContact($oContact);

// change name again and add some additional info....
$oContact->setName('Andri', 'Sardi');
$oContact->addPhone('62822*****2325', VCard::HOME, true);
$oVCard->addContact($oContact);

// and write to file
$oVCard->write('test.vcf', false);



here the result

Filename: test.vcf

BEGIN:VCARD
VERSION:3.0
N:Basri;Hasan;;;
FN:Hasan Basri
ORG:;
X-MS-OL-DEFAULT-POSTAL-ADDRESS:1
TEL;TYPE=CELL,PREF:62822*****2319
END:VCARD
BEGIN:VCARD
VERSION:3.0
N:Fredi;Tegar;;;
FN:Tegar Fredi
ORG:;
X-MS-OL-DEFAULT-POSTAL-ADDRESS:1
TEL;TYPE=CELL:62822*****2319
TEL;TYPE=HOME:62822*****2322
TEL;TYPE=HOME,PREF:62822*****23255
END:VCARD
BEGIN:VCARD
VERSION:3.0
N:Andri;Sardi;;;
FN:Sardi Andri
ORG:;
X-MS-OL-DEFAULT-POSTAL-ADDRESS:1
TEL;TYPE=CELL:62822*****2319
TEL;TYPE=HOME:62822*****2322
TEL;TYPE=HOME:62822*****23255
TEL;TYPE=HOME,PREF:62822*****2325
END:VCARD

  2. Re: Why repeat to other contact below   Reply   Report abuse  
Picture of Stefan Kientzler Stefan Kientzler - 2020-09-27 11:05:19 - In reply to message 1 from Hasan Basri
Hi Hasan,

You always use the same $oContact-object, where you change the name and add further phone numbers - the previously set numbers are not reseted!

You just have to reset the $oContact-object beforehand by creating a new one:

...
$oContact = new VCardContact();
$oContact->setName('Fredi', 'Tegar');
...
$oContact = new VCardContact ();
$oContact->setName('Andri', 'Sardi');


regards, Stefan