下面是一個包含一個人vCard文件的例子:
電子名片2.1:
BEGIN:VCARD
VERSION:2.1
N:Gump;Forrest
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
TEL;WORK;VOICE:(111) 555-1212
TEL;HOME;VOICE: (404) 555-1212
ADR;WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:100 Waters Edge=0D=0ABaytown, LA 30314=0D=0AUnited States of America
ADR;HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:42 Plantation St.=0D=0ABaytown, LA 30314=0D=0AUnited States of America
EMAIL;PREF;INTERNET:[email protected]
REV:20080424T195243Z
END:VCARD
電子名片3.0:
BEGIN:VCARD
VERSION:3.0
N:Gump;Forrest
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;VALUE=URL;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=WORK,VOICE:(111) 555-1212
TEL;TYPE=HOME,VOICE: (404) 555-1212
ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
LABEL;TYPE=WORK:100 Waters Edge\nBaytown, LA 30314\nUnited States of America
ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited States of America
EMAIL;TYPE=PREF,INTERNET:[email protected]
REV:20080424T195243Z
END:VCARD
一旦你有你可以使用一個共振峯中的所有數據說一個字符串變量:
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"vCard.vcf\"");
echo $data;
?>
您還可以,如果你想創建該文件,關閉鏈接到:
$ourFileName = "vCard.vcf";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
我希望這讓你上了軌道,我理解正確你的問題。
答:
<?php
$vCard = "BEGIN:VCARD
VERSION:3.0
N:Gump;Forrest
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;VALUE=URL;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=WORK,VOICE:(111) 555-1212
TEL;TYPE=HOME,VOICE:(404) 555-1212
ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
LABEL;TYPE=WORK:100 Waters Edge\nBaytown, LA 30314\nUnited States of America
ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited States of America
EMAIL;TYPE=PREF,INTERNET:[email protected]
REV:20080424T195243Z
END:VCARD";
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"vCard.vcf\"");
echo $vCard;
?>
上面的代碼將允許用戶下載在$名片舉行的電子名片。在你的情況,你需要添加你自己的數據怎樣看待這件事的例子如下所示:
$vCard = "BEGIN:VCARD
VERSION:3.0
N:Gump;Forrest
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:".$array['title']."
PHOTO;VALUE=URL;TYPE=GIF:".$array['weblink']."
TEL;TYPE=WORK,VOICE:".$array['WORKNUM']."
TEL;TYPE=HOME,VOICE:".$array['HOMENUM']."
ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;".$array['Country']."
LABEL;TYPE=WORK:100 Waters Edge\nBaytown, LA 30314\n".$array['Country']."
ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;".$array['Country']."
LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited States of America
EMAIL;TYPE=PREF,INTERNET:[email protected]
REV:20080424T195243Z
END:VCARD";
感謝蒂姆編輯它 – 422 2011-06-05 01:10:26