📜  用于缩小 javascript 和 css 的 php 函数 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:39.776000             🧑  作者: Mango

代码示例1
$css = '';
$root = $_SERVER['DOCUMENT_ROOT'].'/css/'; //directory where the css lives
$files = explode(',',$_SERVER['QUERY_STRING']);
if(sizeof($files))
{
    foreach($files as $file)
    {
        $css.= (is_file($root.$file.'.css') ? file_get_contents($root.$file.'.css') : '');
    }
}
return str_replace('; ',';',str_replace(' }','}',str_replace('{ ','{',str_replace(array("\r\n","\r","\n","\t",'  ','    ','    '),"",preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!','',$css)))));