php function to minify javascript and css

Solutions on MaxInterview for php function to minify javascript and css by the best coders in the world

showing results for - "php function to minify javascript and css"
Lotta
12 Feb 2019
1$css = '';
2$root = $_SERVER['DOCUMENT_ROOT'].'/css/'; //directory where the css lives
3$files = explode(',',$_SERVER['QUERY_STRING']);
4if(sizeof($files))
5{
6	foreach($files as $file)
7	{
8		$css.= (is_file($root.$file.'.css') ? file_get_contents($root.$file.'.css') : '');
9	}
10}
11return str_replace('; ',';',str_replace(' }','}',str_replace('{ ','{',str_replace(array("\r\n","\r","\n","\t",'  ','    ','    '),"",preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!','',$css)))));