title: Minify a CSS file using PHP
body: <p>The below code removes all newlines and spaces from a CSS file. But the problem is if the CSS file has something like this:</p>
  
  <pre><code>.sample {
      padding: 0px 2px 1px 4px;
  }
  </code></pre>
  
  <p>Output will be :</p>
  
  <pre><code>.sample{padding:0px2px1px4px;}
  </code></pre>
  
  <p>I want that spaces in between  (0px 2px 1px 4px). </p>
  
  <p>Here's the code that I have used :</p>
  
  <pre><code>$str=file_get_contents('sample.css');
  
  //replace all new lines and spaces
  $str = str_replace("\n", "", $str);
  $str = str_replace(" ", "", $str);
  
  //write the entire string
  file_put_contents('sample.css', $str);
  </code></pre>