0

I have this PHP function ( found it on a different page ) to convert CSS data to array its working good for most of CSS but when the CSS has example @media only screen and (max-width: 1800px) on CSS is not showing well.

This is the PHP Function I'm using:

function cssArray( $HTML_DATA_CSS ) {
    preg_match_all( '/(?ims)([a-z0-9\s\,\.\:#_\-@]+)\{([^\}]*)\}/', $HTML_DATA_CSS, $HTML_DATA_CSS_ARR);
    $HTML_DATA_CSS_OUTPUT    =    array();

    foreach ($HTML_DATA_CSS_ARR[0] as $i => $x) {
        $selector = trim($HTML_DATA_CSS_ARR[1][$i]);
        $rules = explode(';', trim($HTML_DATA_CSS_ARR[2][$i]));
        $HTML_DATA_CSS_OUTPUT[$selector] = array();

        foreach ($rules as $strRule) {
            if (!empty($strRule)) {
                $rule = explode(":", $strRule);
                $HTML_DATA_CSS_OUTPUT[$selector][][trim($rule[0])] = trim($rule[1]);
            }
        }
   }

   return $HTML_DATA_CSS_OUTPUT;
}

How I can make the function to work with @media screen too?

Rasclatt
  • 12,382
  • 3
  • 23
  • 33
Matei Zoc
  • 3,341
  • 3
  • 14
  • 15

0 Answers0