【发布时间】:2011-08-07 08:05:49
【问题描述】:
您好,我想将 vCard 格式解析为数组。用户可以上传 vCard 2,1 或 vCard 3.0 我应该能够解析它。我只想将带有 vCard 中名称的电子邮件放入 php 数组中。
我已经尝试过 vcardphp.sourceforge.net。
<?php
require("vcard.php");
$cards = parse_vcards(file('sample.txt'));
print_r($cards);
function parse_vcards($lines)
{
$cards = array();
$card = new VCard();
while ($card->parse($lines)) {
$property = $card->getProperty('N');
if (!$property) {
return "";
}
$n = $property->getComponents();
$tmp = array();
if ($n[3]) $tmp[] = $n[3]; // Mr.
if ($n[1]) $tmp[] = $n[1]; // John
if ($n[2]) $tmp[] = $n[2]; // Quinlan
if ($n[4]) $tmp[] = $n[4]; // Esq.
$ret = array();
if ($n[0]) $ret[] = $n[0];
$tmp = join(" ", $tmp);
if ($tmp) $ret[] = $tmp;
$key = join(", ", $ret);
$cards[$key] = $card;
// MDH: Create new VCard to prevent overwriting previous one (PHP5)
$card = new VCard();
}
ksort($cards);
return $cards;
}
?>
未定义索引:第 146 行 H:\www\vcardphp\vcard.php 中的编码 注意:未定义索引:第 149 行 H:\www\vcardphp\vcard.php 中的 CHARSET
给出的示例代码根本不起作用太多未定义的索引:错误
【问题讨论】:
-
如果对我之前的回答有帮助,你能接受吗stackoverflow.com/questions/6971412/…
-
@Lawrence Cherone 无论如何都在等待更多答案,谢谢
-
-1 用于脚本请求。展示你已经拥有的代码并解释你遇到了什么问题,我可能会重新考虑。
-
您会收到
Undefined index通知,因为 vcard 代码使用索引而不检查它们是否存在。您可以降低错误级别以隐藏这些消息,但这不是最好的主意。修复代码以便不触发这些消息会更好。