/** * Transforms CSS into XML * * @return string $css */ public static function to_xml($css) { # Convert comments self::$comments = array(); $xml = preg_replace_callback('/\\/\\*(.*?)\\*\\//sx', array('NestedSelectors', 'encode_comment'), $css); # Convert imports $xml = preg_replace('/ @import\\s+ (?:url\\(\\s*)? # maybe url( [\'"]? # maybe quote (.*?) # 1 = URI [\'"]? # maybe end quote (?:\\s*\\))? # maybe ) ([a-zA-Z,\\s]*)? # 2 = media list ; # end token /x', "<import url=\"\$1\" media=\"\$2\" />", $xml); # Add semi-colons to the ends of property lists which don't have them $xml = preg_replace('/((\\:|\\+)[^;])*?\\}/', "\$1;}", $xml); # Transform properties $xml = preg_replace('/([-_A-Za-z*]+)\\s*:\\s*([^;}{]+)(?:;)/ie', "'<property name=\"'.trim('\$1').'\" value=\"'.trim('\$2').'\" />\n'", $xml); # Transform selectors $xml = preg_replace('/(\\s*)([_@#.0-9A-Za-z\\/\\+~*\\|\\(\\)\\[\\]^\\"\'=\\$:,\\s-]*?)\\{/me', "'\$1\n<rule selector=\"'.preg_replace('/\\s+/', ' ', trim('\$2')).'\">\n'", $xml); # Close rules $xml = preg_replace('/\\;?\\s*\\}/', "\n</rule>", $xml); # Indent everything one tab $xml = preg_replace('/\\n/', "\r\t", $xml); # Tie it up with a bow $xml = '<?xml version="1.0" ?' . ">\r<css>\r\t{$xml}\r</css>\r"; return simplexml_load_string($xml); }