无需插件实现emlog全站压缩
首先打开你现在用的模板文件
第一步:打开module.php把,把下面代码放到文件中
- <?php
- //全站代码压缩
- function slys($sheli){$initial=strlen($sheli);$sheli=explode("<!--slys-->",$sheli);$count=count($sheli); for($i=0;$i<=$count;$i++){if(stristr($sheli[$i], '<!--slys end-->')){$sheli[$i]=(str_replace("<!--slys end-->", " ", $sheli[$i]));}else{$sheli[$i]=(str_replace("\t", " ", $sheli[$i]));$sheli[$i]=(str_replace("\n\n", "\n", $sheli[$i]));$sheli[$i]=(str_replace("\n", "", $sheli[$i]));$sheli[$i]=(str_replace("\r", "", $sheli[$i]));while (stristr($sheli[$i], ' ')){$sheli[$i]=(str_replace(" ", " ", $sheli[$i]));}}$sheli_out.=$sheli[$i];}$final=strlen($sheli_out);$savings=($initial-$final)/$initial*100;$savings=round($savings,2);$sheli_out.="\n<!--压缩前的大小: $initial bytes; 压缩后的大小: $final bytes; 节约:$savings% -->";return $sheli_out;}
- ?>
第二步:打开footer.php,在最后一行加入下面的代码
- <?php
- //不压缩pre
- function slbys($content){if(preg_match_all('/(crayon-|<\/pre>)/i',$content,$matches)){$content = '<!--slys--><!--slys end-->'.$content;$content.= '<!--slys end--><!--slys-->';}return $content;}slbys($log_content);
- ?>
第四步:找到echo_log.php和page.php这两个文件,把这两个文件中的$log_content用下面代码替换
- slbys($log_content)
