Guest User

VCARD_generator_from_csv

a guest
Oct 13th, 2014
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3. //BEGIN:VCARD
  4. //VERSION:2.1
  5. //N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;=49=6C=6C=C3=A9=73;;;
  6. //FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=49=6C=6C=C3=A9=73
  7. //TEL;CELL:+36 20 910 7199
  8. //END:VCARD
  9. //BEGIN:VCARD
  10. //VERSION:2.1
  11. //N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;=49=6C=64=69=6B=C3=B3;;;
  12. //FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=49=6C=64=69=6B=C3=B3
  13. //TEL;CELL:+36 30 877 7531
  14. //END:VCARD
  15.  
  16. fclose(STDOUT); $STDOUT = fopen('out.valami', 'w');
  17.  
  18. define('d',";");
  19. define('n',"\n");
  20. $f_=file('2.csv',FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  21.  
  22.  
  23. foreach($f_ as $i=>$f){
  24.     $x=explode(d,$f);
  25.     if ($i==0) continue;
  26. //  print_r($x);die;
  27. // 0 => "ker"
  28. // 1 => "vez"
  29. // 2 => "work"
  30. // 3 => "home"
  31. $k=trim(str_replace('"','',$x[0]));
  32. $v=trim(str_replace('"','',$x[1]));
  33. $w=trim(str_replace('"','',$x[2]));
  34. $h=trim(str_replace('"','',$x[3]));
  35. print "BEGIN:VCARD
  36. VERSION:2.1
  37. N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:".quoted_printable_encode($v).";".quoted_printable_encode($k).";;;
  38. FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:".quoted_printable_encode($v." ".$k).(empty($w)?"":"
  39. TEL;WORK:$w").(empty($h)?"":"
  40. TEL;CELL:$h")."
  41. END:VCARD".n;
  42. }
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment