Guest User

csv2vcf

a guest
Oct 13th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3. fclose(STDOUT); $STDOUT = fopen('out.valami', 'w');
  4.  
  5. define('d',";");
  6. define('n',"\n");
  7. $f_=file('2.csv',FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  8.  
  9.  
  10. foreach($f_ as $i=>$f){
  11.     $x=explode(d,$f);
  12.     if ($i==0) continue;
  13. //  print_r($x);die;
  14. // 0 => "ker"
  15. // 1 => "vez"
  16. // 2 => "work"
  17. // 3 => "home"
  18. $k=trim(str_replace('"','',$x[0]));
  19. $v=trim(str_replace('"','',$x[1]));
  20. $w=trim(str_replace('"','',$x[2]));
  21. $h=trim(str_replace('"','',$x[3]));
  22. print "BEGIN:VCARD
  23. VERSION:4.0
  24. N:$k;$v;;;
  25. FN:$v $k".(empty($w)?"":"
  26. TEL;TYPE=work,voice;VALUE=uri:tel:$w").(empty($h)?"":"
  27. TEL;TYPE=home,voice;VALUE=uri:tel:$h")."
  28. REV:20141013T195243Z
  29. END:VCARD".n;
  30. }
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment