1. Go to this page and download the library: Download rondeto/jscontact library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rondeto / jscontact example snippets
use Rondeto\JSContact\Json\JsonEncoder;
use Rondeto\JSContact\VCard\VCardDecoder;
$vCard = <<<VCF
BEGIN:VCARD
VERSION:3.0
UID:urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6
FN:Jane Doe
N:Doe;Jane;;;
EMAIL;TYPE=INTERNET,WORK,PREF:[email protected]
TEL;TYPE=CELL:+33 6 12 34 56 78
END:VCARD
VCF;
$card = (new VCardDecoder())->decode($vCard)[0]->value;
echo (new JsonEncoder())->encode($card, pretty: true);
echo $card->name?->full; // Jane Doe
foreach ($card->emails as $id => $email) {
echo $id, ' ', $email->address, ' ', implode(',', $email->contexts); // EMAIL-1 [email protected] work
}
use Rondeto\JSContact\Json\JsonDecoder;
use Rondeto\JSContact\Json\JsonEncoder;
use Rondeto\JSContact\Model\Card;
use Rondeto\JSContact\Model\EmailAddress;
$result = (new JsonDecoder())->decode($json);
$card = $result->value;
$json = (new JsonEncoder())->encode(new Card(
uid: 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
emails: ['e1' => new EmailAddress('[email protected]', contexts: ['work'], pref: 1)],
));
use Rondeto\JSContact\VCard\VCardDecoder;
use Rondeto\JSContact\VCard\Target;
use Rondeto\JSContact\VCard\VCardEncoder;
use Rondeto\JSContact\VCard\VCardVersion;
// A .vcf file may hold several vCards: one result per vCard.
foreach ((new VCardDecoder())->decode(file_get_contents('contacts.vcf')) as $result) {
$card = $result->value;
}
// Writes vCard 4.0, or the version a Target gives.
$result = (new VCardEncoder())->encode($card, new Target(VCardVersion::V30));
file_put_contents('contact.vcf', $result->value);
use Rondeto\JSContact\Model\Context;
use Rondeto\JSContact\Model\Phone;
$card = (new VCardDecoder())->decode($vCard)[0]->value;
$card->name->full = 'Jane Doe';
$card->emails['EMAIL-1']->address = '[email protected]';
$card->phones['work'] = new Phone('+33 1 23 45 67 89', contexts: [Context::WORK]);
unset($card->notes['NOTE-1']);
$vCard = (new VCardEncoder())->encode($card)->value;
use DeepCopy\DeepCopy;
$copy = (new DeepCopy())->copy($card);
$copy->name->full = 'John Doe'; // $card is unchanged
foreach ($result->issues as $issue) {
echo $issue, "\n"; // e.g. "/emails/e1/pref: expected an integer from 1 to 100, ignored the value"
}
use Rondeto\JSContact\VCard\Dialect\Dialects;
use Rondeto\JSContact\VCard\Target;
use Rondeto\JSContact\VCard\VCardDecoder;
use Rondeto\JSContact\VCard\VCardEncoder;
$results = (new VCardDecoder(dialects: Dialects::all()))->decode($vCards); // the spouse is now in relatedTo
$result = (new VCardEncoder())->encode($card, Target::apple()); // and back to X-ABRELATEDNAMES
use Rondeto\JSContact\Localization\Localizer;
// The Card in French: its "fr" localization applied, or the Card itself without one.
$french = (new Localizer())->localize($card, 'fr')->value;
// The other way: the patch that turns a Card into its French version, to store in localizations.
$patch = (new Localizer())->localization($card, $french);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.