JeroenDesloovere\VCard\VCard::buildVCard PHP Method

buildVCard() public method

Build VCard (.vcf)
public buildVCard ( ) : string
return string
    public function buildVCard()
    {
        // init string
        $string = "BEGIN:VCARD\r\n";
        $string .= "VERSION:3.0\r\n";
        $string .= "REV:" . date("Y-m-d") . "T" . date("H:i:s") . "Z\r\n";
        // loop all properties
        $properties = $this->getProperties();
        foreach ($properties as $property) {
            // add to string
            $string .= $this->fold($property['key'] . ':' . $this->escape($property['value']) . "\r\n");
        }
        // add to string
        $string .= "END:VCARD\r\n";
        // return
        return $string;
    }

Usage Example

 public function testIteration()
 {
     // Prepare a VCard DB.
     $db = '';
     $vcard = new VCard();
     $vcard->addName("Admiraal", "Wouter");
     $db .= $vcard->buildVCard();
     $vcard = new VCard();
     $vcard->addName("Lorem", "Ipsum");
     $db .= $vcard->buildVCard();
     $parser = new VCardParser($db);
     foreach ($parser as $i => $card) {
         $this->assertEquals($card->fullname, $i == 0 ? "Wouter Admiraal" : "Ipsum Lorem");
     }
 }