PHP code example of kigkonsult / phpvcardmgr

1. Go to this page and download the library: Download kigkonsult/phpvcardmgr 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/ */

    

kigkonsult / phpvcardmgr example snippets



namspace Kigkonsult\PhpVcardMgr;

// load an input string
$inputString = ....

// parse Vcard 4.0 input string
$vCards = PhpVcardMgr::factory()->vCard4Parse( $inputString )->getVCards();

// parse Vcard 3.0 input string
// $vCards = PhpVcardMgr::factory()->vCard3Parse( $inputString )->getVCards();

// parse Jcard json input string
// $vCards = PhpVcardMgr::factory()->jCardParse( $inputString )->getVCards();

// parse Xcard XML input string
// $vCards = PhpVcardMgr::factory()->xCardParse( $inputString )->getVCards();

// examine each vcard content
foreach( $vCards as $vCard) {
    if( $vCard->hasProperty( PhpVcardMgr::N )) {
        // Exactly one instance per vCard MAY be present
        $property = $vCard->getProperty( PhpVcardMgr::N );
        $name       = $property->isGroupSet()     // string
            ? $property->getGroupPropName()
            : $property->getPropName();
        $parameters = $property->getParameters(); // array
        $valueType  = $property->getValueType();  // string
        // five-element array : surname/given/additional/prefix/suffix
        $value      = $property->getValue();
            ...
    } // end if
    if( $vCard->hasProperty( PhpVcardMgr::ADR )) {
         // One or more instances per vCard MAY be present
        foreach( $vCard->getProperty( PhpVcardMgr::ADR ) as $property ) {
            $name       = $property->isGroupSet()     // string
                ? $property->getGroupPropName()
                : $property->getPropName();
            $parameters = $property->getParameters(); // array
            $valueType  = $property->getValueType();  // string
            // seven-element array : pobox/ext/street/locality/region/code/country
            $value      = $property->getValue();
            ...
        } // end foreach
    } // end if
    ...
} // end foreach



namspace Kigkonsult\PhpVcardMgr;

use Kigkonsult\PhpVcardMgr\Property\Adr;
use Kigkonsult\PhpVcardMgr\Property\Email;
use Kigkonsult\PhpVcardMgr\Property\N;

// load a Vcard
$vCard = Vcard::factory()
   ->addProperty( Adr::factory( <value> [, <parameters> [, <valueType> [, <group> ]]] )
   ->addProperty( N::factory( <value> [, <parameters> [, <valueType> [, <group> ]]] )
   ->addProperty( Email::factory( <value> [, <parameters> [, <valueType> [, <group> ]]] );

$phpVcardMgr = PhpVcardMgr::factory()->addVCard( $vCard );

// format Vcard 4.0 output string
$outputString = $phpVcardMgr->vCard4Format();

// format Vcard 3.0 output string
// $outputString = $phpVcardMgr->vCard3Format();

// format Jcard json output string
// $outputString = $phpVcardMgr->jCardFormat();

// format Xcard XML output string
// $outputString = $phpVcardMgr->xCardFormat();