读取 vcf (vcard) 标签和值

发布于 2024-11-28 03:24:57 字数 975 浏览 4 评论 0原文

我正在尝试读取 vcf,我已经获取了值,但无法检索类型和前缀。 请看下面的代码

<?php
require_once( 'Contact_Vcard_Parse.php' );
if ( $_FILES['file']['tmp_name'] )
{
  $parse = new Contact_Vcard_Parse();
  $cardinfo = $parse->fromFile( $_FILES['file']['tmp_name'] );
  foreach( $cardinfo as $card )
  {
    $first = $card['N'][0]['value'][0][0];
    $last = $card['N'][0]['value'][1][0];
    $email = $card['EMAIL'][0]['value'][0][0];
    $telcount=0;
    while($telcount<50)
    {       
      $teltitle = $card['TEL'][$telcount]['node'][0][0];
      $tel = $card['TEL'][$telcount]['value'][0][0];
      if(strlen($tel)>=10) 
      { 
        echo 'title : '.$teltitle.'&nbsp;&nbsp;TEL : '.$tel.'<br>'; 
      }
      $telcount++; 
    } 
?>
    email : <?php echo( $email ); ?>
    <br>n : <?php echo( $first ); ?> <br>fn : <?php echo( $last ); ?> <br>
<?php 
  } 
} 
?> 

I am trying to read a vcf, I am already getting the values, but unable to retrieve the type and prefixes.
Please see following code

<?php
require_once( 'Contact_Vcard_Parse.php' );
if ( $_FILES['file']['tmp_name'] )
{
  $parse = new Contact_Vcard_Parse();
  $cardinfo = $parse->fromFile( $_FILES['file']['tmp_name'] );
  foreach( $cardinfo as $card )
  {
    $first = $card['N'][0]['value'][0][0];
    $last = $card['N'][0]['value'][1][0];
    $email = $card['EMAIL'][0]['value'][0][0];
    $telcount=0;
    while($telcount<50)
    {       
      $teltitle = $card['TEL'][$telcount]['node'][0][0];
      $tel = $card['TEL'][$telcount]['value'][0][0];
      if(strlen($tel)>=10) 
      { 
        echo 'title : '.$teltitle.'  TEL : '.$tel.'<br>'; 
      }
      $telcount++; 
    } 
?>
    email : <?php echo( $email ); ?>
    <br>n : <?php echo( $first ); ?> <br>fn : <?php echo( $last ); ?> <br>
<?php 
  } 
} 
?> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

一绘本一梦想 2024-12-05 03:24:57

https://github.com/nuovo/vCard-parser

我之前就是这个 vCard-parser年。它的作用就像一个魅力。您可以在代码中使用该库。

PS:不要重新发明轮子..:)

https://github.com/nuovo/vCard-parser

I was this vCard-parser before an year. Its working like a charm. You can use this library in your code.

PS: Dont reinvent the wheel.. :)

绝不服输 2024-12-05 03:24:57

如果您不想使用任何库:

$VArquivoApple = fopen("./contactsapple.vcf", 'r');
$VArrayApple = [];
while (($VLinha = fgetcsv($VArquivoApple)) !== false)
    $VArrayApple[] = $VLinha[0];
fclose($VArquivoApple);

$VAContatosApple = [];

for ($Vi = 0; $Vi < count($VArrayApple); $Vi++) {
    if ($VArrayApple[$Vi] == "BEGIN:VCARD")
        $VContatoApple = new stdClass();
    if ($VArrayApple[$Vi] != "BEGIN:VCARD" && $VArrayApple[$Vi] != "VERSION:3.0") {
        if ($VArrayApple[$Vi] != "END:VCARD") {
            $VAtributo = isset(explode(":", $VArrayApple[$Vi])[0]) ? explode(":", $VArrayApple[$Vi])[0] : "";
            $VValor = isset(explode(":", $VArrayApple[$Vi])[1]) ? explode(":", $VArrayApple[$Vi])[1] : "";
            $VContatoApple->{$VAtributo} = $VValor;
        } else
            $VAContatosApple[] = $VContatoApple;
    }
}

foreach ($VAContatosApple as $value) {
    var_dump($value);
}

If you don't want to use any libraries:

$VArquivoApple = fopen("./contactsapple.vcf", 'r');
$VArrayApple = [];
while (($VLinha = fgetcsv($VArquivoApple)) !== false)
    $VArrayApple[] = $VLinha[0];
fclose($VArquivoApple);

$VAContatosApple = [];

for ($Vi = 0; $Vi < count($VArrayApple); $Vi++) {
    if ($VArrayApple[$Vi] == "BEGIN:VCARD")
        $VContatoApple = new stdClass();
    if ($VArrayApple[$Vi] != "BEGIN:VCARD" && $VArrayApple[$Vi] != "VERSION:3.0") {
        if ($VArrayApple[$Vi] != "END:VCARD") {
            $VAtributo = isset(explode(":", $VArrayApple[$Vi])[0]) ? explode(":", $VArrayApple[$Vi])[0] : "";
            $VValor = isset(explode(":", $VArrayApple[$Vi])[1]) ? explode(":", $VArrayApple[$Vi])[1] : "";
            $VContatoApple->{$VAtributo} = $VValor;
        } else
            $VAContatosApple[] = $VContatoApple;
    }
}

foreach ($VAContatosApple as $value) {
    var_dump($value);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文