CSS to Array (converter)

  1. function css2array($filename) {
  2.     $css = file_get_contents($filename);
  3.     $css = preg_replace('#\/\*(.*)\*\/#iu', '', $css);
  4.  
  5.     preg_match_all('#(.*){(.*)}#isU', $css, $matches);
  6.     $cnt = sizeof($matches[1]);
  7.     $array = array();
  8.  
  9.     for ($i = 1; $i < $cnt; $i++) {
  10.         $elm = array_filter(explode(';', trim($matches[2][$i])));
  11.         foreach($elm as $k => $v) {
  12.             $keyval = explode(':', $v);
  13.             $array[trim($matches[1][$i])][trim($keyval[0])] = trim($keyval[1]);
  14.         }
  15.     }
  16.  
  17.     return $array;
  18. }
  19.  
  20. echo '<pre>' . print_r(css2array('style.css'), 1);

Реклама

Мы в соцсетях

tw tg yt gt