我正在研究 QR 码解析器,我想知道是否有人知道 MeCard 库或将 MeCard 转换为 VCard 的代码。如果没有,那里有 MeCard 的官方规范文档吗?我知道 NTT DoCoMo 创建了它,但我在上面找不到任何类型的 RFC。
问问题
903 次
1 回答
2
从http://code.google.com/p/zxing/wiki/BarcodeContents,我在http://www.nttdocomo.co.jp/english/service/developer/make/找到了 DoCoMo 的 MeCard 规范的链接内容/条码/功能/应用程序/地址簿/index.html。它非常简单,通过函数调用将其转换为 VCard 应该是微不足道的。
== 编辑 ==
我写了一个小转换函数。以防万一将来有人想要该代码,代码如下:
private function MeCardtoVCard($mecard_text)
{
// Useful References:
// http://www.nttdocomo.co.jp/english/service/developer/make/content/barcode/function/application/addressbook/index.html
// http://code.google.com/p/zxing/wiki/BarcodeContents
// http://en.wikipedia.org/wiki/VCard
// https://theqrplace.wordpress.com/2011/05/02/qr-code-tech-info-mecard-format/
$vcard = '';
if (stripos($mecard_text, "mecard") === 0)
{
$mecard_text = str_replace("\n", "", $mecard_text); // Strip out newlines
$mecard_text = substr($mecard_text,7); // Strip off the MECARD: header
$lines = explode(";", $mecard_text);
if (count($lines) > 0)
{
// Using Version 2.1 because it is the most commonly supported.
$vcard = "BEGIN:VCARD\nVERSION:3.0\n";
foreach($lines as $l)
{
$line_elements = explode(":",$l);
if (count($line_elements) > 1)
{
// Must split into two parts. Not sure how DoCoMo escapes
// data that actually contains a ":", so for now we are presuming
// that the first token is the property name and all other elements
// are the value
$property = $line_elements[0];
$value = implode(":", array_slice($line_elements,1));
if ($property != '' && $value != '')
{
if ($property == 'N')
{
// MeCards only support first and last name.
$tmp = explode(",",$value);
if (count ($tmp) == 1)
{
$vcard .= "N:;" . $tmp[0] . "\n";
}
else
{
$vcard .= "N:" . implode(";",explode(",",$value)) . "\n";
}
}
if ($property == 'TEL')
{
// MeCard does not use card types, so we will presume all of them are type CELL
$vcard .= "TEL:" . $value . "\n";
}
if ($property == 'ADR')
{
// MeCard: "The fields divided by commas (,) denote PO box, room number, house number, city, prefecture, zip code and country, in order."
// VCard: "...post office box; the extended address; the street address; the locality (e.g., city); the region (e.g., state or province); the postal code; the country name" See http://www.ietf.org/rfc/rfc2426.txt 3.2.1
$vcard .= "ADR:" . implode(";",explode(",",$value)) . "\n";
}
if (in_array($property, array('NOTE', 'BDAY', 'URL', 'NICKNAME')))
{
$vcard .= $property . ':' . $value . "\n";
}
}
}
}
$vcard .= "END:VCARD\n";
return $vcard;
}
else
{
return false;
}
}
return false;
}
于 2013-02-12T04:41:45.047 回答