转换电子名片散联系人文件为单.vcf文件
问题描述:
最近,我有一个问题......我想我来回LG U990的Viewty转让我接触到我的iPhone 3GS转换电子名片散联系人文件为单.vcf文件
我出口从我的LG接触到vCard包含所有在一个为
BEGIN:VCARD
VERSION:2.1
N;CHARSET=UTF-8:A;
TEL;CELL;CHARSET=UTF-8:*121#
REV:20120720T081000Z
END:VCARD
现在上面的格式重演所有联系人......在单一文件中的所有地址文件...
我想转换此单一文件到原始文件VCF ...不知道他们不能导入到iPhone也:(
Actualy解决方案:我需要上传原始批量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上面定格式的文件...
我的问题:我所做的是很简单,存在漏洞 - 我们可以做在一个PHP正则表达式上面的迭代和过滤?
这将是一个伟大的学习?
答
-
读取文件并获取上下文的字符串
NSData *String_Data = [NSData dataWithContentsOfFile:yourfilepath]; NSString *theString = [[NSString alloc] initWithData:String_Data encoding:NSUTF8StringEncoding];
-
获得通过每一行的背景下
NSArray *lines = [theString componentsSeparatedByString:@"\n"];
-
运行的循环中的所有行的数组:检查BEGIN的前缀:或END:
NSString * [email protected]""; for (int i=0; i<[lines count];i++){ [stringForVCard stringByAppendingString:[lines objectAtIndex:i] if ([line hasPrefix:@"END"]) [stringForVCard writeToFile:[NSString stringWithFormat:@"Make your own file path for each VCF"] atomically:TRUE encoding:NSUTF8StringEncoding error:nil ]; //Empty the string [email protected]"";}
答
文件结构:
的index.php
联络人.vcf
一(文件夹)
$filename = "contacts.vcf";
$file = file($filename);
$i=1;
$content = "";
foreach ($file as $line)
{
if($line == 'BEGIN:VCARD'."\r\n"){
$content = "";
}
$content .= $line;
if($line == 'END:VCARD'."\r\n"){
$fileName = $i.".vcf";
$ourFileHandle = fopen('a/'.$fileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $content);
fclose($ourFileHandle);
$i++;
echo '<br>' . $i .'
';
}
}
你是什么意思与 “A PHP正则表达式”?一个表达?没有foreach循环?没有内在的循环? 我想知道你在代码中做的所有事情。仅仅在END:VCARD之后进行分割并不容易? – tuergeist 2009-09-07 11:21:05
可能是它更容易的方式...这就是为什么我说它有漏洞...我的意思是preg_replace表达式筛选器等... – foxybagga 2009-09-07 16:15:31