将 vCard 批量联系人文件转换为单个 .vcf 文件
我最近遇到了一个问题...我想将我的联系人从我的 LG U990 Viewty 转移到我的 iPhone 3GS
我将联系人从我的 LG 导出到一个包含所有地址的 vCard 文件,因为
BEGIN:VCARD
VERSION:2.1
N;CHARSET=UTF-8:A;
TEL;CELL;CHARSET=UTF-8:*121#
REV:20120720T081000Z
END:VCARD
现在上述格式对所有用户重复联系人...在那个单个文件中...
我想将这个单个文件转换为原始 vcf 文件...不知道它们也无法导入到 iPhone :(
实际上解决方案:我需要上传原始批量 vCard 文件到一个新的 gmail 帐户联系人并将我的联系人同步到 iTunes 中的该列表...最后我做到了
但是,我制作了这段 PHP 代码,通常作为付费软件提供,人们购买它来破译联系人...这里是下面的代码...免费的
contacts.txt就是那个文件...在文本编辑器中打开该vCard文件并复制内容并制作这个contacts.txt文件,
$filename = "contacts.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd,filesize ($filename));
fclose ($fd);
$delimiter = "BEGIN:VCARD";
$splitcontents = explode($delimiter, $contents);
$counter = "";
$write = "";
$finalName = "";
foreach ( $splitcontents as $color )
{
$counter = $counter+1;
$first = strpos($color, "UTF-8:");
$second = strpos($color, "TEL;");
$name = substr($color, $first+6, $second-$first-7);
$wordChunks = explode(";", $name);
for($i = 0; $i < count($wordChunks); $i++)
{
if(trim($wordChunks[0])!="" || trim($wordChunks[1])!="" )
$finalName .= " ".$wordChunks[$i];
}
$finalName= trim($finalName);
$fileName = $finalName.".vcf";
$ourFileHandle = fopen($fileName, 'w') or die("can't open file");
$stringData = "BEGIN:VCARD ".$color;
fwrite($ourFileHandle, $stringData);
fclose($ourFileHandle);
$finalName = "";
}
这最终将生成上面给出的格式的miltuple .vcf文件...
< strong>我的问题:我所做的非常简单并且有漏洞 - 我们可以在 PHP 正则表达式中进行上述迭代和过滤吗?
这将是一个很好的学习?
I recently had an issue... I wanted to transfer my contacts fro my LG U990 Viewty to my iPhone 3GS
I exported the contacts from my LG to a vCard File containing all the addresses all in one as
BEGIN:VCARD
VERSION:2.1
N;CHARSET=UTF-8:A;
TEL;CELL;CHARSET=UTF-8:*121#
REV:20120720T081000Z
END:VCARD
Now the above format repeated itself for all contacts... in that single file...
I wanted to convert this single file to original vcf files... not knowing that they could not be imported to iPhone also :(
Actualy Solution : I needed to upload the original bulk vCard file to a new gmail's accounts contacts and sync my contacts to that list in iTunes... which finally I did
However, I made this code which is in PHP generally available as a paid software which people buy to decipher the contacts... here is the below code... FREE
contacts.txt is that file ... open that vCard file in text editor and copy the contents and make this contacts.txt file
$filename = "contacts.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd,filesize ($filename));
fclose ($fd);
$delimiter = "BEGIN:VCARD";
$splitcontents = explode($delimiter, $contents);
$counter = "";
$write = "";
$finalName = "";
foreach ( $splitcontents as $color )
{
$counter = $counter+1;
$first = strpos($color, "UTF-8:");
$second = strpos($color, "TEL;");
$name = substr($color, $first+6, $second-$first-7);
$wordChunks = explode(";", $name);
for($i = 0; $i < count($wordChunks); $i++)
{
if(trim($wordChunks[0])!="" || trim($wordChunks[1])!="" )
$finalName .= " ".$wordChunks[$i];
}
$finalName= trim($finalName);
$fileName = $finalName.".vcf";
$ourFileHandle = fopen($fileName, 'w') or die("can't open file");
$stringData = "BEGIN:VCARD ".$color;
fwrite($ourFileHandle, $stringData);
fclose($ourFileHandle);
$finalName = "";
}
this will finally make miltuple .vcf files of format given above...
MY QUESTION : WHAT I DID WAS VERY SIMPLE AND HAS LOOPHOLES - CAN WE DO THE ABOVE ITERATION AND FILTERING IN A PHP REGULAR EXPRESSION ?
it would be a great learning ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
读取文件并获取上下文的字符串
获取上下文中所有行的数组
Run for 循环遍历每行:检查 BEGIN: 或 END: 的前缀
Read the file and get a string of the context
Get array of all the lines in the context
Run for Loop through each line: Check prefix for BEGIN: or END:
文件结构:
index.php
contact.vcf
a(文件夹)
file structure:
index.php
contacts.vcf
a(folder)