将 vCard 批量联系人文件转换为单个 .vcf 文件

发布于 2024-08-03 14:38:18 字数 1647 浏览 2 评论 0原文

我最近遇到了一个问题...我想将我的联系人从我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自演自醉 2024-08-10 14:38:18
  1. 读取文件并获取上下文的字符串

    NSData *String_Data = [NSData dataWithContentsOfFile:yourfilepath];
    NSString *theString = [[NSString alloc] initWithData:String_Data 编码:NSUTF8StringEncoding];
    
  2. 获取上下文中所有行的数组

    NSArray *lines = [theString elementsSeparatedByString:@"\n"];
    
  3. Run for 循环遍历每行:检查 BEGIN: 或 END: 的前缀

    NSString * stringForVCard=@"";
    for (int i=0; i<[行数];i++){
    [stringForVCard stringByAppendingString:[行 objectAtIndex:i]
    if ([行有前缀:@"END"]) 
    [stringForVCard writeToFile:[NSString stringWithFormat:@"为每个 VCF 创建自己的文件路径"] 原子地:TRUE 编码:NSUTF8StringEncoding 错误:nil ];
    //清空字符串
    stringForVCard=@"";}
    
  1. Read the file and get a string of the context

    NSData *String_Data = [NSData dataWithContentsOfFile:yourfilepath];
    NSString *theString = [[NSString alloc] initWithData:String_Data encoding:NSUTF8StringEncoding];
    
  2. Get array of all the lines in the context

    NSArray *lines = [theString componentsSeparatedByString:@"\n"];
    
  3. Run for Loop through each line: Check prefix for BEGIN: or 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=@"";}
    
倚栏听风 2024-08-10 14:38:18

文件结构:

index.php

contact.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 .'
';
    }
}

file structure:

index.php

contacts.vcf

a(folder)

$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 .'
';
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文