title: Merging multiple CSS files into one in PHP
body: <p>i'm working on a script that generates multiple CSS into one. And Here is the script. </p>
  
  <pre><code>    $full_string = "";
  
      foreach($allfiles as $curfile =&gt; $file) {           
          $file = $PATH[$curfile] . $file;
          $file_open = fopen($file , 'r');
          $concat = "\n" . fread($file_open , filesize($file)) . "\n";
          $full_string .= $concat;
          fclose($file_open);
      }
  
      return $full_string;
  </code></pre>
  
  <p>Here i'm combining all the CSS files into one. But the problem now is i have to compare the current CSS($file) with another css(let's consider it as <code>overrider.css</code>). And if $file is having a style like,</p>
  
  <pre><code>h1 {
      color: white; 
      background: teal; 
      FONT-FAMILY: arial, helvetica, lucida-sans, sans-serif; 
      FONT-SIZE: 18pt; 
      FONT-STYLE: normal; 
      FONT-VARIANT: normal;
  }
  
  body 
  {
      font-family: arial;
      FONT-SIZE: 14px; 
  }
  </code></pre>
  
  <p>and if overrider.css is having a style like, </p>
  
  <pre><code>body 
  {
      font-family: Calibri;
      color: #3E83F1; 
  }
  </code></pre>
  
  <p>Then final CSS(output.css) generated should be,</p>
  
  <pre><code>h1 {
      color: white; 
      background: teal; 
      FONT-FAMILY: arial, helvetica, lucida-sans, sans-serif; 
      FONT-SIZE: 18pt; 
      FONT-STYLE: normal; 
      FONT-VARIANT: normal;
  }
  
  body 
  {
      font-family: Calibri;
      FONT-SIZE: 14px;
      color: #3E83F1;
  }
  </code></pre>
  
  <p>Here, since style for body in <code>override.css</code> have <code>font-family</code>, it replaces the font-family property in original CSS and since the color is a new property which is not present in ($file) which is original CSS file, so it should add the property to original CSS file. So how to achieve this in PHP, since i don't have any idea on parsing CSS. Any idea on this would be greatly appreciated. </p>
  
  <p>Please note that i need to generate a new CSS file by giving the input as file1($file) and file2(override.css) and we need to genrate output.css with the styles overridden.</p>
  
  <p>Thanks in advance.</p>