Skip to content

Instantly share code, notes, and snippets.

@kreamweb
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreamweb/8ccc50a6251b73e495ba to your computer and use it in GitHub Desktop.
Save kreamweb/8ccc50a6251b73e495ba to your computer and use it in GitHub Desktop.
Parser a web font style
<?php
$handle = fopen("style.css", "r");
$file = 'config.json';
$arr = array();
if ($handle) {
$key = '';
while (($line = fgets($handle)) !== false) {
preg_match('/[\w-]+/', $line, $matches );
preg_match('/\"([[:ascii:]]+?)\"/', $line, $matches2 );
if( ! empty( $matches )){
if( $matches[0] != 'content'){
$key = $matches[0];
}
}
if( ! empty( $matches2 ) && $matches[0] == 'content'){
$arr[$matches2[1]] = $key;
}
}
print_r($arr);
file_put_contents($file, json_encode($arr));
} else {
// error opening the file.
}
fclose($handle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment