parse css with media queries and other end cases to php array -


id break css file php array. have code:

function parsecss($css_str) {     $css = array();      // todo include external css     $css_str = preg_replace('/(@import\s+["\'].+["\'];)/', "", $css_str);      // strip line endings , both single , multiline comments     $css_str = preg_replace('/\s*(?!<\")\/\*+[^\*]+\*+\/(?!\")\s*/', "", $css_str);      $css_class = explode("}", $css_str);      while(list($key, $value) = each($css_class)){          $acssobj = explode("{", $value);         $cssselector = strtolower(trim($acssobj[0]));         if($cssselector){                 // regular class not in media query                 $cssprops[] = $cssselector;                 $a = explode(";", $acssobj[1]);                 while(list($key, $val0) = each($a)){                     if(trim($val0)){                         $acsssub = explode(":", $val0);                         $catt = strtolower(trim($acsssub[0]));                         if(isset($acsssub[1])){                             $acssitem[$catt] = trim($acsssub[1]);                         }                     }                 }                 if((isset($css[$cssselector])) && ($css[$cssselector])){                     $acssitem = array_merge($css[$cssselector], $acssitem);                 }                 $css[$cssselector] = (isset($acssitem)) ? $acssitem : null ;                 unset($acssitem);                }         if(strstr($cssselector, ",") && !strstr($cssselector, "@media")){             $atags = explode(",", $cssselector);             print_r($atags);             foreach($atags $key0 => $value0){                 $css[$value0] = $css[$cssselector];             }             unset($css[$cssselector]);         }     }     unset($css_str, $css_class, $acsssub, $acssitem, $acssobj);     return $css; } 

but doesn't return me css file media queries supposed be. , if there ":" sign in css value -for example ie expression that:

top:expression((-20+(document.documentelement.clientheight ?document.documentelement.clientheight/2:document.body.clientheight/2)+(ignoreme = document.documentelement.scrolltop ? document.documentelement.scrolltop:document.body.scrolltop))+'px') 

its giving cutted code.

so result should that:

array (     [selector] => array (             [prop] => value             [prop2] => value     )      [@media handheld,only screen , (max-width:320px)] => array(         [selector] => array(                 [prop] => value                 [prop2] => value         )     ) ) 

how make work?

solved that! i've used csstidy parse css, , job beautifully! http://csstidy.sourceforge.net/index.php


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -