kreamweb
11/5/2014 - 9:03 PM

Parser a web font style

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);