Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php vcard显示为纯文本_Php_Vcf Vcard - Fatal编程技术网

php vcard显示为纯文本

php vcard显示为纯文本,php,vcf-vcard,Php,Vcf Vcard,我的网站上有一个新功能,允许用户获取vcard文件。此功能从我的数据库读取数据(此功能可以工作)并生成vcard 文件是:vcard.php,我将用户id作为GET传递 然后我用这个id获取所有信息 我的问题是,当我想要获取vcard时,它显示为文本。以下是我的代码的简化版本: <?php class Vcard { public function __construct() { $this->props = array(); } public functi

我的网站上有一个新功能,允许用户获取vcard文件。此功能从我的数据库读取数据(此功能可以工作)并生成vcard

文件是:vcard.php,我将用户id作为GET传递

然后我用这个id获取所有信息

我的问题是,当我想要获取vcard时,它显示为文本。以下是我的代码的简化版本:

<?php

class Vcard {

  public function __construct() {
    $this->props = array();
  }

  public function setName($family, $first) {
    $name = $family . ';' . $first . ';';
    $this->props['N'] = $name;
    if(!isset($this->props['FN'])) {
      $display = $first . ' ';
      $display .= $family;
      $this->props['FN'] = trim($name);
    }
  }
  /* and all the rest of my props */
  public function get() {
    $text = 'BEGIN:VCARD' . "\r\n";
    $text.= 'VERSION:2.1' . "\r\n";
    foreach($this->props as $key => $value) {
      $text .= $key . ':' . $value . "\r\n";
    }
    $text.= 'REV:' . date("Y-m-d") . chr(9) . date("H:i:s") . "\r\n";
    $text.= 'MAILER:My VCard Generator' . "\r\n";
    $text.= 'END:VCARD' . "\r\n";
    return $text;
  }
}

$v = new Vcard();
$v->setName('Smith', 'John');
echo $v->get();
给定

您当然需要在
echo$v->get()之前添加以下行

以便告知客户端浏览器它将接收VCard文件

header('Content-Type: text/vcard');