[ create a new paste ] login | about

Link: http://codepad.org/yrTCeGF7    [ raw code | output | fork ]

PHP, pasted on Aug 22:
<?php
function minify_css($css){
/* remove comments */
$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
/* remove tabs, spaces, newlines, etc. */
$css = str_replace(array("\r\n","\r","\n","\t",'  ','    ','     '), '', $css);
/* remove other spaces before/after ; */
$css = preg_replace(array('(( )+{)','({( )+)'), '{', $css);
$css = preg_replace(array('(( )+})','(}( )+)','(;( )*})'), '}', $css);
$css = preg_replace(array('(;( )+)','(( )+;)'), ';', $css);
return $css;
}



$css_input=<<<EOF
      div {
          margin:auto 1em;
      }
      #code {
          float:left;
          width:50%;
      }
      #html {
          float:right;
          width:50%;
      }
      #code2 {
          margin-right:1em;
      }
      #html2 {
          margin-left:1em;
      }
      #main textarea {
          width:100%;
          height:10em;
      }
      #html2 textarea {
          float:right;
      }
      #options {
          clear:both;
      }
      #divstyles {
          width:50%;
      }
      #preview {
          padding-bottom: 3em;
      }
      #footer {
          border-top:1px dotted #000;
      }
      #footer p {
          text-align:center;
          font-size:75%;
      }
EOF;
$css=minify_css($css_input);
echo "<style>$css</style>";
?>


Output:
1
<style>div{margin:auto 1em}#code{float:left;width:50%}#html{float:right;width:50%}#code2{margin-right:1em}#html2{margin-left:1em}#main textarea{width:100%;height:10em}#html2 textarea{float:right}#options{clear:both}#divstyles{width:50%}#preview{padding-bottom: 3em}#footer{border-top:1px dotted #000}#footer p{text-align:center;font-size:75%}</style>


Create a new paste based on this one


Comments: