title: Parsing vCard in php
body: <p>Hi i want to parse vCard format to a array. User may upload vCard 2,1 or vCard 3.0 i should  be able to parse it. I just want the email with names in the vCard in to a php array.</p>
  
  <p>i have tried vcardphp.sourceforge.net.</p>
  
  <pre><code>&lt;?php
  
  require("vcard.php");
  
  $cards = parse_vcards(file('sample.txt'));
  print_r($cards);
  
  
  function parse_vcards($lines)
  {
      $cards = array();
      $card = new VCard();
      while ($card-&gt;parse($lines)) {
          $property = $card-&gt;getProperty('N');
          if (!$property) {
              return "";
          }
          $n = $property-&gt;getComponents();
          $tmp = array();
          if ($n[3]) $tmp[] = $n[3];      // Mr.
          if ($n[1]) $tmp[] = $n[1];      // John
          if ($n[2]) $tmp[] = $n[2];      // Quinlan
          if ($n[4]) $tmp[] = $n[4];      // Esq.
          $ret = array();
          if ($n[0]) $ret[] = $n[0];
          $tmp = join(" ", $tmp);
          if ($tmp) $ret[] = $tmp;
          $key = join(", ", $ret);
          $cards[$key] = $card;
          // MDH: Create new VCard to prevent overwriting previous one (PHP5)
          $card = new VCard();
      }
      ksort($cards);
      return $cards;
  }
  ?&gt;
  </code></pre>
  
  <p>Undefined index: ENCODING in H:\www\vcardphp\vcard.php on line 146
  Notice: Undefined index: CHARSET in H:\www\vcardphp\vcard.php on line 149</p>
  
  <p>and the sample code given doesnt work at all Too many  Undefined index: errors</p>