https://zy.xzku.cn/ https://zy.xzku.cn/
首页
  • 首页
  • 软件工具
  • 壁纸图库
  • 游戏相关
  • 电视盒子
  • 值得一看
  • 资源杂烩
搜索历史 清空
写文章

登录

账号密码登录
扫码登录
扫码登录
请使用手机扫码登录
注册登录即表示同意用户协议和隐私政策
软件工具
实用工具 音乐软件 追剧软件 小说动漫 电脑软件 图像影音 上传下载
壁纸图库
值得一看
网盘剧集 网盘电影
站长资源
资源杂烩
活动线报
娱乐吃瓜
游戏相关
电视盒子
推荐 最新
emlog 无插件实现网站源码压缩
夕子库xzku 2024-11-21

emlog 无插件实现网站源码压缩

在以往的 emlog 优化教程中,相信都是使用的代码压缩插件,今天主要是分享插件的代码版本,也就是不使用插件,直接将代码写在 module.php 中就可以,好吧,又消灭一个插件! 以下代码是写在 module.php 里面 <?php function em_compress_html($buffer) { $initial = strlen($buffer); $buffer = explode("<!--em-compress-html-->", $buffer); $count = count($buffer); for ($i = 0; $i <= $count; $i++) { if (stristr($buffer[$i], '<!--em-compress-html no compression-->')) { $buffer[$i] = (str_replace("<!--em-compress-html no compression-->", " ", $buffer[$i])); } else { $buffer[$i] = (str_replace("\t", " ", $buffer[$i])); $buffer[$i] = (str_replace("\n\n", "\n", $buffer[$i])); $buffer[$i] = (str_replace("\n", "", $buffer[$i])); $buffer[$i] = (str_replace("\r", "", $buffer[$i])); while (stristr($buffer[$i], ' ')) { $buffer[$i] = (str_replace(" ", " ", $buffer[$i])); } } $buffer_out .= $buffer[$i]; } $final = strlen($buffer_out); $savings = ($initial - $final) / $initial * 100; $savings = round($savings, 2); $buffer_out .= PHP_EOL . "<!--压缩前的大小: $initial bytes; 压缩后的大小: $final bytes; 节约:$savings% -->"; return $buffer_out; } ?> 以下代码放在 footer.php 最末尾(即结尾处) <?php if (_g('compress_html') == 'open') { $html = ob_get_contents(); ob_get_clean(); echo em_compress_html($html); } ?> 以上的代码有一个模板设置判断语句,其代码为以下(放在 options.php 里面) 'compress_html' => array( 'type' => 'radio', 'name' => '网站源码压缩', 'description' => '将HTML的空格和空行删除,保留pre里面的格式,压缩输出的HTML~', 'values' => array('open' => '开启', 'close' => '关闭'), 'default' => 'open' ), 如果你想要实现不压缩 pre(就是网页中插入的代码,这样就能显示代码的排版)中的代码,要在 module.php 里面的加入下面代码。 <?php function unCompress($content) { if (preg_match_all('/(<pre|<\/pre>)/i', $content, $matches)) { $content = '<!--em-compress-html--><!--em-compress-html no compression-->' . $content; $content .= '<!--em-compress-html no compression--><!--em-compress-html-->'; } return $content; } ?> 然后找到模版文件夹下的 echo_log.php(文章内容页面)、page.php(评论页面)文件中的 $log_content 替换掉。 <?php echo $log_content; ?> // 替换为 <?php echo unCompress($log_content); ?> 不压缩 pre 的解决方法二,直接把第一步的 module.php 里面的 em_compress_html 修改一下 <?php function em_compress_html($buffer) { $initial = strlen($buffer); $buffer = preg_replace('/<pre/', '<!--em-compress-html--><!--em-compress-html no compression--><pre', $buffer); $buffer = preg_replace('/<\/pre/', '<!--em-compress-html no compression--><!--em-compress-html--></pre', $buffer); $buffer = explode("<!--em-compress-html-->", $buffer); $count = count($buffer); for ($i = 0; $i <= $count; $i++) { if (stristr($buffer[$i], '<!--em-compress-html no compression-->')) { $buffer[$i] = (str_replace("<!--em-compress-html no compression-->", " ", $buffer[$i])); } else { $buffer[$i] = (str_replace("\t", " ", $buffer[$i])); $buffer[$i] = (str_replace("\n\n", "\n", $buffer[$i])); $buffer[$i] = (str_replace("\n", "", $buffer[$i])); $buffer[$i] = (str_replace("\r", "", $buffer[$i])); while (stristr($buffer[$i], ' ')) { $buffer[$i] = (str_replace(" ", " ", $buffer[$i])); } } $buffer_out .= $buffer[$i]; } $final = strlen($buffer_out); $savings = ($initial - $final) / $initial * 100; $savings = round($savings, 2); $buffer_out .= PHP_EOL . "<!--压缩前的大小: $initial bytes; 压缩后的大小: $final bytes; 节约:$savings% -->"; return $buffer_out; } ?>

397 27 0
Emlog教程代码压缩

热门文章

  • 1 气质贤妻 办公室黑丝端木蓉 国漫女神 ​​​
  • 2 [夸克下载][埃利亚斯][WEB-MKV/2.37G][法语中字][1080P][2024最新刺激动作枪战]
  • 3 PC迅雷游戏加速器免费获取口令兑换会员,白嫖会员权益!
  • 4 迅猛兔加速器解锁版 3.2.31国内外手游加速器
  • 5 全集 [夸克下载][10月16日精品付费短剧合集][共27部][WEB-MKV/9.9G][国语中字][1080P]

标签

  • 碧瑶
  • 동그란
  • 手机软件
  • 免费虚拟主机
  • 照片编辑
  • 图片处理
  • 安卓虚拟机
  • 虚拟大师
  • 虚拟系统
  • 激活工具
  • 装B神器
  • 陆雪琪
  • 云曦
  • 宁姚
  • 清漪
  • 金瓶儿
  • 圣采儿
  • 天穹
  • macOS
  • 美人鱼
  • 美杜莎
  • 唐火儿
  • 夏倾月
  • 虚天神藤
  • 元瑶
  • 玄衣
  • 应用分身
  • 虚拟定位
  • 火灵儿
  • 文件管理
  • 抖音助手
  • 网站推荐
  • 休闲娱乐
  • 马来西亚
  • Wordpress
  • Emlog
  • VPN
  • 主题壁纸
  • 代码压缩
  • Emlog教程
  • 爱情
  • 怀旧服
  • 穿越火线
  • 系列
  • 全集
  • 开源版
  • 剧情
  • 欧美
  • 2023
  • 黑科技工具

最新文章

  • 1 音乐搜索v2.0.0版提供付费音乐的免费下载服务
  • 2 搜狗输入法V12.10最新会员内购版
  • 3 甜蜜话语聊天库1.0去更新广告纯净版
  • 4 余额装测试版1.0自定义设置 WX 支付宝余额
  • 5 无影云电脑7.5.1专属个人云电脑 白嫖30天云电脑

微语

  • 夕子库xzku
    2024-11-29 13:21

  • 夕子库xzku
    2024-11-15 19:03

    q

关于 友链 rss
赣ICP备2024048016号

备案号: