Skip to content

Instantly share code, notes, and snippets.

@mircobabini
Last active December 14, 2015 04:39
Show Gist options
  • Save mircobabini/5029479 to your computer and use it in GitHub Desktop.
Save mircobabini/5029479 to your computer and use it in GitHub Desktop.
Google contacts vcards cleaner
<?
require "vcard-extendible.php"; // https://github.com/nuovo/vCard-parser
class GCards extends vCard {
/**
* @return bool
*/
public function hasTel () {
return (sizeof ($this->tel) > 0);
}
public function hasMail () {
return (sizeof ($this->email) > 0);
}
}
// lot of vcards
$cards = new GCards ("cards.vcf");
// var_dump (sizeof ($cards));
$buffer = "";
// $notempty = array ();
foreach ($cards as $card)
{
if ($card->hasTel () || $card->hasMail ())
{
// $notempty[] = $card;
$buffer .= (string)$card;
}
}
// var_dump (sizeof ($notempty));
file_put_contents ('notempty.vcf', $buffer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment