这是我使用的代码。
$vcard = "";
while ($row = $result->fetch_assoc()) {
// Get contact information from the database
$name = $row['name'];
$email = $row["email"];
$phone = $row["wa_no"];
// Split the name into individual words
$nameParts = explode(' ', $name);
// Get the last name
$lastName = array_pop($nameParts);
// Set the first name and middle name
$firstName = '';
$middleName = '';
// If there are remaining name parts after removing the last name
if (!empty($nameParts)) {
// The first part is the first name
$firstName = array_shift($nameParts);
// The remaining parts (if any) are the middle name
$middleName = implode(' ', $nameParts);
}
// Create a new vCard entry
$vcard .= "BEGIN:VCARD\r\n";
$vcard .= "VERSION:3.0\r\n";
$vcard .= "N:$lastName;$middleName;$firstName;SL365 ;\r\n";
$vcard .= "FN:$name-SL365\r\n";
$vcard .= "TEL;type=CELL;waid=$phone:" . substr($phone, 0, 2) . " " . substr($phone, 2) . "\r\n";
$vcard .= "EMAIL;TYPE=INTERNET:$email\r\n";
$vcard .= "END:VCARD\r\n";
}
// Set the HTTP headers to download the vCard file
$today = date("YmdHis");
header("Content-Type: text/x-vcard");
header("Content-Disposition: inline; filename=SLcontacts$today.vcf");
// Output the vCard data
echo $vcard;
是的,可以在 .vcf 文件中包含同一用户的多个电话号码。这是一种常见的做法,尤其是对于出于个人、工作、家庭等不同目的而使用不同电话号码的个人。
创建 .vcf 文件时,您可以包含多个电话号码字段,并为每个字段添加适当的标签。以下是具有四个电话号码的用户的 .vcf 文件中电话号码部分的示例结构:
使用此格式:
BEGIN:VCARD
VERSION:3.0
N:Lastname;Firstname;;;
FN:Firstname Lastname
TEL;TYPE=CELL:+1234567890
TEL;TYPE=WORK:+1234567891
TEL;TYPE=HOME:+1234567892
TEL;TYPE=OTHER:+1234567893
EMAIL:[email protected]
END:VCARD