私はQRコードパーサーに取り組んでいますが、MeCardライブラリ、またはMeCardをVCardに変換するコードを誰かが知っているかどうか疑問に思っています。そうでない場合は、MeCardの公式仕様書はありますか?NTTドコモが作成したことは知っていますが、RFCは見つかりません。
質問する
903 次
1 に答える
2
From http://code.google.com/p/zxing/wiki/BarcodeContents, I found a link to DoCoMo's specification for MeCard, at http://www.nttdocomo.co.jp/english/service/developer/make/content/barcode/function/application/addressbook/index.html. It is pretty dirt simple and converting it to a VCard with a function call should be pretty trivial.
== EDIT ==
I wrote a little conversion function. Just in case anyone in the future wants the code, it is below:
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 に答える