Skip to content

Instantly share code, notes, and snippets.

@Zenger
Created January 23, 2014 07:20
Show Gist options
  • Save Zenger/8574336 to your computer and use it in GitHub Desktop.
Save Zenger/8574336 to your computer and use it in GitHub Desktop.
Generate a list of webfonts from google.
<?php
define('APIKEY', 'your-api-key');
$request = file_get_contents('https://www.googleapis.com/webfonts/v1/webfonts?key='. APIKEY);
$fh = fopen('list.txt', 'w');
fwrite($fh, $request);
fclose($fh);
$content = json_decode($request) ;
$txt = "";
foreach($content->items as $item)
{
$txt .= "\t\t". '"'. $item->family . '"' . " => " . '"'. $item->family. '",' . "\n";
}
$txt = rtrim($txt, ",");
$today = date('d-m-Y H:i:s');
$php = "
<?php
// As of {$today}
class GoogleWebFonts
{
static \$fonts = array(\n{$txt});
public static function register( \$font )
{
self::\$fonts[\$font] = array( \$font );
}
public static function get( \$font )
{
return self::\$fonts[\$font];
}
public static function all()
{
return self::\$fonts;
}
public static function getList()
{
\$list = array();
foreach(self::\$fonts as \$font => \$item)
{
\$list[\$font] = \$font;
}
return \$list;
}
}
?>";
$fh = fopen('GoogleWebFonts.php', 'w');
fwrite($fh, $php);
fclose($fh);
echo "done!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment