我最近遇到了一个问题...我想将我的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中:(
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常规表达式进行上述迭代和过滤吗?
这将是一个很好的学习?
答案 0 :(得分:1)
读取文件并获取上下文的字符串
NSData *String_Data = [NSData dataWithContentsOfFile:yourfilepath];
NSString *theString = [[NSString alloc] initWithData:String_Data encoding:NSUTF8StringEncoding];
获取上下文中所有行的数组
NSArray *lines = [theString componentsSeparatedByString:@"\n"];
通过每行运行循环:检查BEGIN的前缀:或END:
NSString * stringForVCard=@"";
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
stringForVCard=@"";}
答案 1 :(得分:0)
文件结构:
的index.php
联络人.vcf
A(文件夹)
$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 .'
';
}
}